Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Foreach Rename VM with $name plus XX

$
0
0

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

 

}

}


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>