Public/Update-VirtualMachineAliasesSetup.ps1

<#
.SYNOPSIS
    Updates the Hyper-V Virtual Machine aliases for the WDK VM and enables remote management alias on the set VM.
.DESCRIPTION
    This script updates the Hyper-V Virtual Machine aliases for the specified WDK VM. It allows you
.PARAMETER Name
    The name of the WDK virtual machine.
.PARAMETER Credential
    The credential to use for connecting to the WDK virtual machine.
.EXAMPLE
    # after that you can use Enter-Vm, Invoke-Vm, Copy-FileToVm Stop-VirtualMachine and Start-VirtualMachine aliases to manage the WDK VM remotely.
    Update-VirtualMachineAliases -Name "Windows 11 WDK Environment" -Credential (Import-Clixml "${env:USERPROFILE}\.cert\wdkcert.xml")
     
    # or use directly Get-Vm Cmdlet
    Get-VM | ? {$_.Name -match "WDK"} | Update-VirtualMachineAliases -Credential (Import-Clixml "MyCert.xml")
#>

function Update-VirtualMachineAliases {
    param(
        [Parameter(Mandatory = $false, Position = 0, ValueFromPipelineByPropertyName = $true)]
        [string] $Name,

        [Parameter(Mandatory = $false, Position = 1, ValueFromPipelineByPropertyName = $true)]
        [pscredential]$Credential,

        [Parameter(Mandatory = $false)]
        [switch]$Silent
    )

    if ($Name) {
        $script:VirtualMachineManager.VMName = $Name
    }

    if ($Credential) {
        $script:VirtualMachineManager.Credential = $Credential
    }

    if (-not $Silent) {   
        $script:VirtualMachineManager
    }
}