Hi,
I need some help.
I wannt to do a foreach loop with import of some VM´s, shut them down and rename each VM to the original VM Name plus "_xx_delete"
so for example vm " VMADC01 will renamed to VMADC01_xx_delete after shutdown,
I have the loop but now clue how to rename it
######################
$importDatei = "C:\scripts\VMliste.txt"
$vmlist = Import-Csv -Path $importDatei -Delimiter ";"
foreach ($vm in $vmlist)
{
$vm1 = Get-VM -Name $vm.name -ErrorAction:SilentlyContinue
if ($vm1.powerstate -eq "poweredon"-and $vm1.Guest.State -eq "Running")
{
$vm1 | Shutdown-VMGuest -Confirm:$false | out-null
Write-Host $vm1.name "go offline soft"
sleep -Seconds 3
}
elseif($vm1.powerstate -eq "poweredon"-and $vm1.Guest.State -eq "NotRunning")
{
$vm1 | where {$_.Guest.State -eq "NotRunning"} | Stop-VM -Confirm:$false | out-null
Write-Host $vm1.name "go offline hard"
sleep -Seconds 3
}
else
{write-host $vm1.name "is already offline" | Format-Table -AutoSize
}
}