#Get vm name and check if it exists within vCenter $Name = Read-Host "Enter the Name or Names using wildcard * of the VM e.g Server*" $VM = Get-VM $Name | Where {($_.Powerstate -eq 'PoweredOn')} DO{ IF ($VM){ $Isname = $True Write-Host "VM FOUND :)" -Foreground GREEN } ELSE { $Isname = $False Write-Error "VM NOT FOUND! :(" -Background RED -Foreground Black } }UNTIL ($Isname -ne $False) #Run script in Guest Write-Host "Running Script..." $ScriptText = "PowerShell.exe -NoProfile -Command ""([wmiclass]'ROOT\ccm:SMS_Client').SetAssignedSite('GSY')""" Invoke-VMScript -VM $VM -ScriptText $ScriptText -ScriptType bat -GuestUser administrator -GuestPassword *Password*