DCSIMG
Guest blog - Eliminate the risk by knowing your disk - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

Guest blog - Eliminate the risk by knowing your disk

ושוב אני , כמובטח, אצל שי מתארח
והפעם בעסקי דיסקים ונפחים עסקינן
ה"דבא ים" (DBA) בקשו שהדיסק להם ידווח
שידעו על מצבו לפני שיוכרז בר-מינן
לעקוב ולדעת, לזהות כשלפתע צומח
טענו שהשו"ב ,בתיאור התראותיו , קמצן
ומנגנון הדוח"ות מסורבל ואותם הוא רוצח

סקריפטו (שי) אומר, דולי עזוב הדברים , רשום הפרטים
כתוב אפליקציה מתאימה לאנשי הטבלאות
באדום צבע את החריגים ותאפשר שינוי ספים
בממשק נוח לבריות, שבנתונים יהיה קל לצפות
עכשיו לאחר התנסות קצרה "הדבא ים" מרוצים

אולי גם אתם רוצים, בכלי הנ"ל להתנסות
עבורכם, בתחתית הפוסט קישורים לקבצים
קובץ התקנה עבור האפליקציה לחלונות
וסקריפט לאנשים שאוהבים מסכים כחולים

 

I'm very pleased to have on my blog a friend, colleague and a PowerShell convert, Dolav Hadas. This will be his second guest blog, the first one was in Hebrew. Dolav, the stage is yours.


For those who prefer the blue screen (not the BSOD Smile ) Get-FreeSpace is a function which delivers logical disk information from local and remote computers. Before querying a remote machine the function sends a ping request to the target machine. The function will continue querying disk information, only for those machines that answered its ping request. The Unreachable Destinations are saved in memory, and can be shown on screen by using the ListUnreachable Switch parameter.

A list of remote computers can be added to the command line by writing the machine names or by reading it from a text file:

Get-FreeSpace –ComputerName Server1,Server2,Server3,Server4 …

OR

“Server1”,”Server2”,”Server3”,”Server4” | Get-FreeSpace

OR

Get-Content .\ServersList.txt | Get-FreeSpace

 

The result is the same:

image

 

The attached script also contains a filter, written by Shay Levy, that can be used to mark low disk space rows:

Get-FreeSpace -ComputerName Server1,Server2,server3,server4 | Out-Color -FilterScript {$_.FreeSpacePercent -lt 10} | Format-Table 

 

image

 

For detailed help just type:

Get-Help Get-FreeSpace –Full

 

For just the examples type:

Get-Help Get-FreeSpace -Examples

 

Get-DiskInfo, The GUI version (written with Sapien's Primal Forms 2009 Editor). The GUI version has more features and in my opinion, much easier to use:

image

 

1. The first step is to write down a list of computers in the left pane

image

 

2. Then click the imagebutton to get disk data. The results are listed in the following table

a. Use image to mark low disk space rows

 

image

 

3. For your convenient, you can change or sort columns.

4. The Computer List is saved and you can reload it by clicking the imagebutton.

5. You can export the disk data to a CSV file, by pressing the imagebutton.

6. Press image to open the .chm help file.

 

You can download the setup file for the GUI version and the script file for the console version HERE.

Comments

Twitter Trackbacks for Guest blog - Eliminate the risk by knowing your disk - Shay Levy [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Guest blog - Eliminate the risk by knowing your disk - Shay Levy         [microsoft.co.il]        on Topsy.com

# February 6, 2011 6:43 PM

Powershell : Get Freespace information of your disks « MS Tech BLOG said:

Pingback from  Powershell : Get Freespace information of your disks « MS Tech BLOG

# February 11, 2011 12:27 AM

Powershell : Get Freespace information of your disks « MS Tech BLOG said:

Pingback from  Powershell : Get Freespace information of your disks « MS Tech BLOG

# February 11, 2011 12:27 AM

Powershell : Get Freespace information of your disks « MS Tech BLOG said:

Pingback from  Powershell : Get Freespace information of your disks « MS Tech BLOG

# February 11, 2011 12:27 AM

Eli said:

Sounds great but where can i get the function from? is it cmdlet?

# March 5, 2011 9:37 PM

ScriptFanatic said:

@Eli, look for the download link at the end of the post (Click on 'HERE').

# March 8, 2011 3:48 PM

Eli said:

it looks like that in the PS Command window the foreach function is broken. here's what i enter:

PS C:\Users\v-elisag> Get-Content .\Documents\Execution\HostsList-Test.txt |  Get-FreeSpace

and then i get:

       Begin querying computers

*************************************

Get-WmiObject : Invalid namespace

At C:\Users\v-elisag\Documents\WindowsPowerShell\Modules\GetFreeSpace\Get-FreeSpace.ps1:64 char:9

+                 gwmi <<<<  win32_logicalDisk -ComputerName $Computer -Filter "DriveType=3" | Foreach-Object{

   + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException

   + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

I've try to outsmart it:

$comps=Get-Content .\Documents\Execution\HostsList-Test.txt

then

foreach ($comp in $comps) {Get-FreeSpace -computerName $comp}

and got the same error.

# March 22, 2011 5:53 PM

ScriptFanatic said:

@Eli

By looking at the error you get back (Invalid namespace) it looks like WMI on one of the computers in the text file is corrupt/broken. Does it happen for all computers in the file? Can you Identify the failing computer?

# March 23, 2011 10:17 AM

Eli said:

@ScriptFanatic

thanks for your reply.

I've took all machines out of the text file and left single server.

with:

Get-Content .\ServerList.txt | Get-Freespace

it fails with the same error.

with the same server as in the list:

"ServerName" | Get-FreeSpace

it succeeded.

# March 24, 2011 12:59 PM

Eli said:

@ScriptFanatic

The long error message for the single server failure:

"Get-WmiObject : Invalid namespace

At C:\Users\v-elisag\Documents\WindowsPowerShell\Modules\GetFreeSpace\Get-FreeSpace.ps1:64 char:9

+                 gwmi <<<<  win32_logicalDisk -ComputerName $Computer -Filter "DriveType=3" | Foreach-Object{

   + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException

   + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Test-Connection : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argume

nt that is not null or empty and then try the command again.

At C:\Users\v-elisag\Documents\WindowsPowerShell\Modules\GetFreeSpace\Get-FreeSpace.ps1:58 char:41

+             $Ping = Test-Connection -ComputerName <<<<  $Computer -Quiet -Count $PingCount

   + CategoryInfo          : InvalidData: (:) [Test-Connection], ParameterBindingValidationException

   + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestConnectionCommand

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument

that is not null or empty and then try the command again.

At C:\Users\v-elisag\Documents\WindowsPowerShell\Modules\GetFreeSpace\Get-FreeSpace.ps1:64 char:41

+                 gwmi win32_logicalDisk -ComputerName <<<<  $Computer -Filter "DriveType=3" | Foreach-Object{

   + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException

   + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand"

# March 24, 2011 1:01 PM

ScriptFanatic said:

Can you make sure that the server name has no leading or trailing space characters.

# March 24, 2011 1:36 PM

Eli said:

@ScriptFanatic

that's it! i had trailing space on the servers name.

IMHO it can be easily handled by the script.

thanks.

# March 24, 2011 2:08 PM

ScriptFanatic said:

Agree, Dolav is going to fix it and release it on his new blog, check it out - blogs.microsoft.co.il/.../doli. Meanwhile, you can fix your local version by editing the script file. Change the following command (in the process block):

$Computer = $Computer.TrimEnd('$')

To this:

$Computer = $Computer.Trim().TrimEnd('$')

 

 

# March 24, 2011 2:23 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: