This morning I need to shutdown all the VMs in a folder as it was Christmas eve. So I created the following script to do just that!
## PowerCLI clone off all VMs in a folder
## Version 1.0 12/24/2020
## Tom Fenton
##
#
# Specify vCenter Server, vCenter Server username and vCenter Server user password
$vCenter=”176.16.0.0″
$vCenterUser=”administrator@vmwarelab.local”
$vCenterUserPassword=”FatChance!”
#
# Specify vCenter Server Virtual Machine & Templates folder
$Folder = “CallCenter”
#
# Specify the vSphere Cluster
$Cluster = “dhci-cl”
#
#
# End of user input parameters
#_______________________________________________________
#
write-host “Connecting to vCenter Server $vCenter” -foreground green
Connect-viserver $vCenter -user $vCenterUser -password $vCenterUserPassword -WarningAction 0
$rnd = Get-Random -Minimum 60 -Maximum 420
write-host “Power off all the VMs in $Folder” -ForegroundColor Red
Get-Folder “$Folder” | get-vm |Where-object {$_.powerstate -eq “poweredon”} | Stop-VM -Confirm:$false -RunAsync