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

Hyper-V Logon Failure: the user has no been granted the requested logon type at this computer (0x80070569)

Issue: When performing a live migration of a guest VM, this error occurs: '...Failed to…

Resume All Guest VMs in a Clustered Hyper-V Environment

# resumeAllVms.ps1 # Significance: this script is useful in a Clustered Hyper-V environment # where…

Kubernetes: Cert-Manager x509 ECDSA verification failure

Symptoms Error from server (InternalError): error when creating "kimconnect-cert.yaml": Internal error occurred: failed calling webhook…