Posted On January 26, 2023

PowerShell: How to Change Guest VM Names in Virtual Machine Manager

kimconnect 0 comments
blog.KimConnect.com >> Virtualization >> PowerShell: How to Change Guest VM Names in Virtual Machine Manager
# changeGuessVmNameInVmm.ps1
# The following script prepend all VM's matching certain pattern
# This is useful to mark VM's to be deleted for ease of administration

$nameLike='test'
$prefix='_decom 02-01-2020_ '

$targetVms=Get-SCVirtualMachine|?{$_.Name -like "*$nameLike*"} 
foreach($targetVm in $targetVms){
    try{
        $oldName=$targetVm.Name
        $newName="$($prefix+$oldName)"
        $changed=Set-SCVirtualMachine -VM $targetVm -Name $newName
        if($changed.name -eq $newName){
            write-host "$oldName's name has been changed to $newName" -foregroundcolor Green
        }else{
            write-host "$oldName's name has NOT been changed to $newName" -foregroundcolor Red
        }
    }catch{
        write-warning $_        
    }    
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

How to Remove ‘Ghost’ VMs with Status ‘Off-Critical’ or ‘Saved-Critical’

Issue: Resolution: get-vm|?{$_.State -in @('OffCritical','SavedCritical')}|remove-vm -force

How to Import Files Into a Docker Container

1. Use SCP to copy files to the remote server while logged onto the local…

Virtual Machine Networking Error 15011

Creating New Logical Network $logicalNetworkID="somehash-hash-hash" $newNetworkName='Test Network' $subnet="192.168.500.0/24" $logicalNetwork = Get-SCLogicalNetwork -ID $logicalNetworkID $vmNetwork =…