Hi All
Very basic question please.
I am new to PowerCLI and learning by playing around pretty much.
I've put a basic script together to report on VM's with snapshots.
The script below works fine but I need to round the numbers under the Size GB col.
Could any please assist with a one liner and perhaps a bit of an explanation.
Sure.
- one of the strong points of PowerShell is that it can use a pipeline. This allows passing objects from 1 cmdlet to the next cmdlet.
- one a Select-Object you can what is called a 'calculated expression'. It consists of a Name ('N') and an EXpression ('E')
- PowerShell is built on .NET, so you can use the .NET functions and methods. The [Math] one has a Round method
Get-Snapshot |
Select-Object @{N='VM';E={$_.VM.Name}}, Created,
@{N='SizeGB';E={[math]::Round($_.SizeGB,1)}},Description
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi All
I have the following piece of code:
Select-Object @{N='VM';E={$_.VM.Name}},
@{N='Description';E={$_.Description}},
@{N='Created';E={$_.Created.ToString("dd/MM/yyyy")}},
@{N='Age';E={( Get-Date ) - $_.Created}},
@{N='SizeGB';E={[math]::Round($_.SizeGB,1)}}
I would like to only display the differance in days under the age col.
Currently it outputs days:hrs:min:sec:ticks
Change that line to
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference