Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: parse result of disk space

$
0
0

One of the best things about PowerShell is that you almost never have to “parse” anything. Get-WmiObject gives you rich objects with strongly-typed data. Select-Object and Out-GridView (in your code) are fine for formatting the data to be displayed to an end-user, but if you intend to keep doing things with the data afterward, you should just keep a reference to the original objects. For example:

# Get the Win32_LogicalDisk objects and hold on to them for later use.

$drives = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computer (Get-Content .\Servers.txt)

# Display some formatted output with Out-GridView

$drives |
Select DeviceID,@{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} |
Out-GridView

# Now you can continue to work with $drives, as needed.

Viewing all articles
Browse latest Browse all 13067

Trending Articles