#Parameters param( [Parameter(Mandatory=$true)] [string] $VMId ) #Check VMId $ret = get-vm |Where {$_.Id -eq $VMId} if ($ret -eq $null) { Write-Output "VM not found. Aborting." } #Get status of Hyper-V VM and save it $VMName = $ret.Name $ret = Get-VM -Name $VMName if($ret.State -eq "Running") { rite-Output "Stopping VM '$VMName'..." Stop-VM -Name $VMName -Save } else { Write-Output "VM '$VMName' is already stopped. No action taken." }