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!