PowerCLI VM power state report and delete from disk
# Found 3/5/17
# https://vmscribble.com/powercli/powercli-vm-power-state-report-and-delete-from-disk
# Add the PowerCLI snapin to PowerShell
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Your textfile of VMs can have an * at the end in case someone added -decomm to the end.
$vCenter = Read-Host "Enter the FQDN of your vCenter"
$textfile = Read-Host "Enter the path to the list of VMs ex. c:scriptspowerstatevms.txt"
$listofvms = Get-Content -path $textfile
Write-Host "VM-PowerState.csv created in the same folder as this script"
# Connect to your vCenter
Connect-VIServer $vCenter
# Command
Get-VM $listofvms | select Name, PowerState | sort Name | Select Name, PowerState | Export-csv -Path "VM-PowerState.csv"
# Disconnect from the vCenter
Disconnect-VIServer $vCenter -Confirm:$false
You will see the “web3” power on VM error our.
# Found 3/5/17
# https://vmscribble.com/powercli/powercli-vm-power-state-report-and-delete-from-disk
# Add the PowerCLI snapin to PowerShell
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Input
$vCenter = Read-Host "Enter the FQDN of your vCenter"
$textfile = Read-Host "Enter the path to the list of VMs ex. c:scriptsdelete-vmsvms.txt"
$listofvms = Get-Content -path $textfile
# Connect to your vCenter
Connect-VIServer $vCenter
# DeleteFromDisk command
$listofvms | foreach { Remove-vm $_ -DeleteFromDisk -Confirm:$false }
# Disconnect from the vCenter
Disconnect-VIServer $vCenter -Confirm:$false