How to get nice Logical Disk State View using PowerShell Grid Widget

Hi there after a long break. This time I’d like to share with you some nice example of using PowerShell Grid Widget. There are already lots of good blog posts, just to mention Stefan Stranger’s walkthrough: and official blog post of MOM Team: There are already guides on how to create a nice widget view, so I will just briefly mention high-level steps needed to perform widget creation:

1. Create a Dashboard View with Grid Layout and 1 Cell in it.



2. Create a Widget inside of created Dashboard by clicking Add Widget in it.

3. Choose PowerShell Grid Widget layout.

4. Name it like “Windows Server Logical Disk State and Space”

5. In the Script pane insert following script:

$disks = Get-SCOMClass -Name "Microsoft.Windows.Server.LogicalDisk" | Get-SCOMClassInstance
foreach ($disk in $disks)
   $query = GET-WMIOBJECT –query “SELECT * from win32_logicaldisk where DeviceID = '$disk'" -ComputerName $disk.Path | Select-Object Size, FreeSpace
   $size = $query.Size
   $free = $query.FreeSpace
   $percent = $free / $size
   $pervalue = "{0:P0}" -f $percent
   $sizeGB = "{0:N1}" -f ($size / 1024 / 1024 / 1024)
   $freeGB = "{0:N1}" -f ($free / 1024 / 1024 / 1024)

   $dataobject = $ScriptContext.CreateFromObject($disk, "Id=Id,HealthState=HealthState,DisplayName=DisplayName,Server=Path", $null)
   $dataobject["% Free"] = $pervalue
   $dataobject["Size (in GB)"] = $sizeGB
   $dataobject["Free Space (in GB)"] = $freeGB

6. Save the Widget and wait a moment.

Be aware that this widget will collect data only on the account you are logged in for those disks and if you need to get it done for disks in untrusted domain, workstations etc., you need to change script to pass proper credentials.


So on each refresh the state dasboard will reflect the space and size on demand.



This example is provided “AS IS” with no warranty expressed or implied. Run at your own risk.
The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of Microsoft.

**Always test in your lab first**  Do this at your own risk!! The author will not be held responsible for any damage you incur when making these changes!

Comments (7)
  1. Steve Harris says:

    Hi Łukasz

    I receive a ‘time out’ error when using the above script within a 2012 R2 CU2 environment.

    I opened up PowerShell ISE and I execute the script and it returns hundreds of errors such as "you cannot call a method on a null-valued expression", "cannot index into a null array"


    You cannot call a method on a null-valued expression.
    At line:12 char:4
    + $dataobject = $ScriptContext.CreateFromObject($disk, "Id=Id,HealthState=Healt …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Any ideas?

  2. Jazeel says:

    Hi Lukasz,

    What i have to add or change in the script to target it to specific group of servers only?

  3. Majid says:

    Hi Lukasz
    thanks for helpful script.
    What i have to add or change in the script to target it to specific group of servers only?
    i need to similar script for memory an processor

  4. Tiago Simoes says:

    For specific servers, create a group with the disks from those servers and use Get-SCOMGroup -DisplayName "GROUPNAME" | Get-SCOMClassInstance

Comments are closed.

Skip to main content