I have a one liner that I put together (mostly stolen from here) that reports on guest disk space usage:
*Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, @{N="FreeSpace"; E={::round($_.freespace / 1GB,1)}}, @{N="Capacity"; E={::round($_.Capacity / 1GB,0)}}, @{N="PercFree"; E={*::Round((100 * ($_.FreeSpace / $_.Capacity)),1 )}}**
This works great but I want to add a "where" clause to filter out "c:\". I tried the following:
*Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, @{N="FreeSpace"; E={::round($_.freespace / 1GB,1)}}, @{N="Capacity"; E={::round($_.Capacity / 1GB,0)}}, @{N="PercFree"; E={*::Round((100 * ($_.FreeSpace / $_.Capacity)),1 )}} | where path -ne "C:\")**
But I get an error saying that "A parameter cannot be found that matches parameter name 'path'"
Can some one point me in the right direction? My native language is VBScript. I am still getting the hang of PS.
Thansk,
Dan
You could do that like this
Get-VM | where { $_.PowerState -eq "PoweredOn" } | ` Get-VMGuest | Select VmName -ExpandProperty Disks | ` Select VmName, Path, @{N="FreeSpace"; E={math::round($_.freespace / 1GB,1)}}, @{N="Capacity"; E={math::round($_.Capacity / 1GB,0)}}, @{N="PercFree"; E={math::Round((100 * ($_.FreeSpace / $_.Capacity)),1 )}} | ` where {$_.Path -ne "C:\"}
The object that is placed in the pipe can be accessed in the Where-Object filter with $_.
And you want to test the Path property of the object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do that like this
Get-VM | where { $_.PowerState -eq "PoweredOn" } | ` Get-VMGuest | Select VmName -ExpandProperty Disks | ` Select VmName, Path, @{N="FreeSpace"; E={math::round($_.freespace / 1GB,1)}}, @{N="Capacity"; E={math::round($_.Capacity / 1GB,0)}}, @{N="PercFree"; E={math::Round((100 * ($_.FreeSpace / $_.Capacity)),1 )}} | ` where {$_.Path -ne "C:\"}
The object that is placed in the pipe can be accessed in the Where-Object filter with $_.
And you want to test the Path property of the object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the help!
I tried the $_. but I didn't know it had to be in the {}.
Very much appreciated,
Dan