I'm building a script to snapshot all of our servers just before patching (we have over 200), my script is supposed to check the name and if it does not have a string in the name its not supposed to patch, but I can not get it to check the name. I have used just about every comparison I can think of, but I'm fairly new to powershell.
Connect-VIServer -User "someusername" -Password "*********" -Server "FQDN" $VMS = get-vm | where { ($_.PowerState -eq "PoweredOn") } $date=Get-Date -Format dd-MMM-yyyy $number = $VMS.Count $num = 1 $time = Get-Date foreach ($vm in $vms) { If ($vm.name -notcontains "_rogue_") { New-Snapshot -VM "$VM" -Name ("$date" + "_Patch_cycle") -Description "Auto Snap taken before Patch cycle $date" -Memory write-host "Snapshot on $VM completed, $num of $number @ $time" $num = $num +1} }
the snap potion works, it's just snapping every host, and I have 20 - 30 host with _rogue_ in the middle of the name, thta I would like to NOT snap, as they don't really need it... Ideally I have two Strings I would like to exclude, but I could not get the singe string to work let alone 2 strings