Public/Enter-VirtualMachine.ps1
|
<#
.SYNOPSIS Enters a remote in a remote PowerShell session on the user preferred virtual machine. .DESCRIPTION This function uses the Enter-PSSession cmdlet to enter a remote PowerShell session on the virtual machine specified by the user. The user must have previously registered the virtual machine aliases using the Register-VirtualMachineAliases function. .EXAMPLE # Register the virtual machine aliases for the WDK VM Register-VirtualMachineAliases -Name "Windows 11 WDK Environment" -Credential (Import-Clixml "${env:USERPROFILE}\.cert\wdkcert.xml") # Enter a remote PowerShell session on the WDK VM Enter-VirtualMachine .NOTES Requires the Hyper-V PowerShell module. The user must have the necessary permissions to access the virtual machine and establish a remote session. Use the Register-VirtualMachineAliases function to set up the virtual machine aliases before using this function. #> function Enter-VirtualMachine { if (-not $script:VirtualMachineManager) { throw "Virtual Machine aliases are not registered. Run Register-VirtualMachineAliases first." } Enter-PSSession -Credential $script:VirtualMachineManager.Credential -VMName $script:VirtualMachineManager.VmToStart } |