共用方式為


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: https://blogs.technet.com/b/stefan_stranger/archive/2014/04/28/new-powershell-grid-widget-walkthrough.aspx and official blog post of MOM Team: https://blogs.technet.com/b/momteam/archive/2014/04/24/new-widgets-and-dashboard.aspx. 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.

image

 

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
$ScriptContext.ReturnCollection.Add($dataobject)
}

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.

image

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

 

 

Disclaimer:
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

  • Anonymous
    January 01, 2003
    Super Awesome!
  • Anonymous
    January 01, 2003
    Very nice, thanks!
  • Anonymous
    January 01, 2003
    Nice one!
  • Anonymous
    January 07, 2015
    The comment has been removed
  • Anonymous
    January 28, 2015
    Hi Lukasz,

    What i have to add or change in the script to target it to specific group of servers only?
  • Anonymous
    September 07, 2015
    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
    thanks
  • Anonymous
    April 06, 2016
    For specific servers, create a group with the disks from those servers and use Get-SCOMGroup -DisplayName "GROUPNAME" | Get-SCOMClassInstance