Guest blog – Eliminate the risk by knowing your disk

February 6, 2011

ושוב אני , כמובטח, אצל שי מתארח
והפעם בעסקי דיסקים ונפחים עסקינן
ה”דבא ים” (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.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

9 comments

  1. EliMarch 5, 2011 ב 21:37

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

    Reply
  2. ScriptFanaticMarch 8, 2011 ב 15:48

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

    Reply
  3. EliMarch 22, 2011 ב 17:53

    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.

    Reply
  4. ScriptFanaticMarch 23, 2011 ב 10:17

    @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?

    Reply
  5. EliMarch 24, 2011 ב 12:59

    @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.

    Reply
  6. EliMarch 24, 2011 ב 13:01

    @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"

    Reply
  7. ScriptFanaticMarch 24, 2011 ב 13:36

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

    Reply
  8. EliMarch 24, 2011 ב 14:08

    @ScriptFanatic
    that’s it! i had trailing space on the servers name.
    IMHO it can be easily handled by the script.

    thanks.

    Reply
  9. ScriptFanaticMarch 24, 2011 ב 14:23

    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(‘$’)

     

     

    Reply