Powercli one liners
Find RDMs in your environment
This process will find any RDMs in your environment. I’ve found it useful as we attempt to phase out use of RDMs.
Get-VM | Get-HardDisk -DiskType “RawPhysical”,”RawVirtual” | Select Parent,Name,ScsiCanonicalName,DiskType
Cleanup Backup Snapshots
A common problem in our environment are “Consolidate” snapshots that our backup process leaves behind. Find and irradicate those with this quick command:
Get-VM | Sort Name | Get-Snapshot | Where { $_.Name.Contains(“Consolidate”) } | Remove-Snapshot
Find Lost or Unknown Snapshots
Our backup process also seems to leave behind orphaned snapshots, snapshots vCenter or ESX no longer knows about. vCenter sees the VM in linked-clone mode, where the VMX file points to a snapshot VMDK instead of the original parent.
Compare-Object $(Get-VM | SORT | Get-Harddisk | WHERE { $_.Filename -like "0000" } | SELECT @{Name="VM";Expression={$_.Parent}} | Get-Unique -asstring) $(Get-VM | Get-Snapshot | SELECT VM | Get-Unique -asstring) -Property VM
Rescan All HBA and New Storage
get-cluster -name “clustername” | get-vmhost | Get-VMHostStorage -RescanAllHBA
All Hosts in VC:
get-vmhost | Get-VMHostStorage -RescanAllHBA
List of VM’s created in the last 14 days
Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(–14) | where {$_.Gettype().Name-eq “VmCreatedEvent” -or$_.Gettype().Name-eq “VmBeingClonedEvent” -or$_.Gettype().Name-eq “VmBeingDeployedEvent”} |SortCreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage
List of VM’s removed in the last 14 days
Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(–14) |where {$_.Gettype().Name-eq “VmRemovedEvent”} |SortCreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage