Set-HyperVAdvancedSessionMode
Hyper-V: Configures Advanced Session Mode on a Hyper-V host
#Requires -Version 5.1
#Requires -Modules Hyper-V
[CmdletBinding()]
Param (
[string]$ComputerName = "localhost",
[PSCredential]$Credential,
[Parameter(Mandatory = $true)]
[bool]$Enabled
)
Process {
try {
$params = @{
'ComputerName' = $ComputerName
'EnableEnhancedSessionMode' = $Enabled
'Confirm' = $false
'ErrorAction' = 'Stop'
}
if ($Credential) { $params.Add('Credential', $Credential) }
Set-VMHost @params
$hostInfo = Get-VMHost -ComputerName $ComputerName -ErrorAction Stop
$result = [PSCustomObject]@{
ComputerName = $hostInfo.Name
EnhancedSessionModeEnabled = $hostInfo.EnableEnhancedSessionMode
Action = "AdvancedSessionModeConfigured"
Status = "Success"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch {
throw
}
}Specifies the name of the Hyper-V host. Defaults to the local machine.
Specifies the credentials to use for the remote connection.
Specifies whether Enhanced Session Mode should be enabled ($true) or disabled ($false).