Selecting parts of objects
You can use the Select-Object
cmdlet to create new, custom PowerShell objects that contain
properties selected from the objects you use to create them. Type the following command to create a
new object that includes only the Name and FreeSpace properties of the Win32_LogicalDisk
WMI class:
Get-CimInstance -Class Win32_LogicalDisk |
Select-Object -Property Name, FreeSpace
Name FreeSpace
---- ---------
C: 50664845312
With Select-Object
you can create calculated properties to display FreeSpace in gigabytes
rather than bytes.
Get-CimInstance -Class Win32_LogicalDisk |
Select-Object -Property Name, @{
label='FreeSpace'
expression={($_.FreeSpace/1GB).ToString('F2')}
}
Name FreeSpace
---- ---------
C: 47.18
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.