Hi All,
I not new to using powerCLI but this is my first script. I'm trying to create a script to list the following so I can put it in a report:
Below is what I've come up with so far I get some of the info but no all and in the format I would like. Can some on please tell me where I'm going wrong?
$creds = Get-VICredentialStoreItem -file “C:\Scripts\vclogin.xml”
Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password
Get-Cluster| Get-VM | Get-Snapshot | Where-Object {$_. Created -lt (Get-Date). AddDays(-0)} |
Select-Object -Property @{Name=’Cluster’;Expression={$_.VMHost.Parent}}, VM, Name, @{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}}, Created | Format-Table
Try like this
Get-Cluster| Get-VM | Get-Snapshot |
Where-Object {$_. Created -lt (Get-Date). AddDays(-7)} |
Select-Object -Property @{Name=’Cluster’;Expression={$_.VM.VMHost.Parent.Name}},
VM, Name,
@{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}},
@{N='Days Old';E={[math]::Round((New-TimeSpan -Start $_.Created -End (Get-Date)).TotalDays,0)}} |
Format-Table
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure exactly what you want.
Perhaps you can show what you currently get as output, and what you would like to get in the output ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the reply! I've attached what I'm getting for an output. What I'm looking to get is a report that shows the following:
VM name, Cluster, the number of snapshots, age in days of the snap shot and the storage consumed by the snapshot. My output is Cluster without data, VM name, size in Gb which is fine because the snap shot is small (lab testing) and the date created. From what I have gotten so far, I think I just need to figure out how to convert the Created property into a calculation but I don't think I can and get data from the Cluster Property.
May I ask where can I get your vSphere Performance Reporting with PowerCLI: Automating vSphere Performance Reports book? Its not available anywhere.
That book has been canceled
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
Get-Cluster| Get-VM | Get-Snapshot |
Where-Object {$_. Created -lt (Get-Date). AddDays(-7)} |
Select-Object -Property @{Name=’Cluster’;Expression={$_.VM.VMHost.Parent.Name}},
VM, Name,
@{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}},
@{N='Days Old';E={[math]::Round((New-TimeSpan -Start $_.Created -End (Get-Date)).TotalDays,0)}} |
Format-Table
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oh sorry to hear that I was looking forward to reading it. I do have the PowerCLI Cookbook that helped me get as far as I did.
Well, it's still on my personal list.
One day it will be there :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I like the code you shared for Cluster | VM | Snapshot way back ion Jan 28, 2016 10:10 PM in this post. I'm looking for a modification so that it's Datastore | VM | Snapshot. The resulting table would display:
Datastore Name VM Name Snapshot Name Size Days Old
I'm tripped up on the code.
You mean like this?
Get-Datastore -PipelineVariable ds | Get-VM | Get-Snapshot |
Where-Object {$_. Created -lt (Get-Date). AddDays(-7)} |
Select-Object -Property @{Name=’Datastore’;Expression={$ds.Name}},
VM, Name,
@{N="Size";E={"{0:N2} GB" -f ($_.SizeGB)}},
@{N='Days Old';E={[math]::Round((New-TimeSpan -Start $_.Created -End (Get-Date)).TotalDays,0)}} |
Format-Table
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference