invoke-command -scriptblock {
#using script block to bypass Execution Policy massage
#install VMware.PowerCLI follow below steps
#run powershell as admin
#run the command to intall
#Install-Module -Name VMware.PowerCLI
#Install-Module VMware.PowerCLI -Scope CurrentUser
#Set-executionpolicy remotesign
#Import-Module VMware.PowerCLI
#Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
#now install steps over restart powershell
#To disable this warning and set your preference use the following command and restart PowerShell
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false
#Connect to vCenter
$Server = Connect-VIServer -Server 192.168.12.97 -User xxx@vsphere.local -Password xxxxxxxxxx
#Gets the list of all Hosts in a specific folder
$vmHosts = Get-VMHost -Location Singapore
Foreach($vmHost in $vmHosts)
{
$vmHost.name
$vms = Get-vmhost -name $vmHost.name | Get-VM | where { $_.PowerState -eq "PoweredOn"}
Foreach ($vm in $vms){
#use condition if want to suspend specific vm
if($vm.Name -eq "xx-xxx-Win2016-DevVM" -or $vm.Name -eq "xx-xxx-Win2016-TGS" -or $vm.Name -eq "xx-xxxx-Win10-HP")
{
Suspend-VM $vm -Confirm:$false -RunAsync
sleep -Seconds 5
}
}
}
Disconnect-VIServer -Server $Server -Confirm:$false
read-host “Press ENTER to continue...”
}
download the RDP file using RDP file you can connect to your VM
Comments
Post a Comment