PowerShell - Disk Check with Win32_LogicalDiskPowerShell - Disk Check with Win32_LogicalDiskOur mission is to investigate and interrogate a computer's logical disk. Goals include discovering the size of each volume, and how much free space is available. We also have pure PowerShell goals, for example, to examine the 'Select' statement, and to control the display with -groupby, |sort and -auto. Topics for PowerShell Disk Check
♣ Trusty Twosome (Get-Help and Get-Member)When you discover a new PowerShell command, it benefits from being surveyed with what I call the 'Trusty Twosome'. I guarantee that if you research with Get-Help and Get-Member then you will reveal new scripting possibilities for get-WmiObject Win32_LogicalDisk. To see what I mean try these two commands: 1) get-Help get-WmiObject Get-help unearths useful parameters such as -class and -computerName (-computer also works). 2) get-WmiObject Win32_LogicalDisk |get-Member -MemberType property Get-Member reveals a whole host of properties that you don't normally see in Explorer. Example 1a - Display Logical Disk InformationLet us start with a simple script to display disk information. We begin by using just the -query parameter combined with an SQL-like select statement. # PowerShell cmdlet to display Logical Disk information Note Out-GridView: PowerShell v 2.0 introduces a new cmdlet to control data display. See more on how to pipe the results into out-GridView. Example 1b - Display Disk Size and FreeSpaceIn the example below, I introduce a variable called $Item to control the output. If you would like to refine the output to your specification, then research with get-Member. The parameter -auto helps to 'tighten' the data display. # PowerShell cmdlet to display a disk's free space Example 1c - PowerShell Innovationsi) The example provides structure to the data thanks to the -groupby command in the last line. ii) However,
this example's neatest technical achievement is: iii) It also introduces the idea of interrogating other machines on the network, for this it uses the -computerName, incidentally, -computer works just as well.
Naturally, the first thing to alter in the script below is: # PowerShell cmdlet to display a disk's free space Example 1d - Where command addedThe new feature of the example below is the 'Where MediaType' filter. By now I hope that you have started adjusting the script according to your needs. $Item = @("DeviceId", "MediaType", "Size", "FreeSpace")
˚
Example 2 Win32_DiskPartitionThe first purpose of this script is to remind you that WMI can access at least 500 win32 objects, of which 20 contain the word 'Disk'. The second purpose is to show what information is revealed by a specific object namely: win32_DiskPartion.
# PowerShell cmdlet to display a disk's partition information. Learning PointsNote 1: Remember get-Member. Here is a classic situation to employ get-Member to discover what other properties are available for fin-tuning $Item. This is the command to explore: get-wmiObject win32_DiskPartition | get-member. Note 2: The basis of this script was kindly supplied by Jimmy May. Please send me your ideas for scripts.
Guy Recommends: SolarWinds LANSurveyor
|
||||||
Download my ebook:
|
*
|
|
|
|
Home Copyright © 1999-2009 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |