Skip to content

Instantly share code, notes, and snippets.

@Nora-Ballard
Last active January 10, 2016 02:15
Show Gist options
  • Save Nora-Ballard/6611bde5dab8d168ec18 to your computer and use it in GitHub Desktop.
Save Nora-Ballard/6611bde5dab8d168ec18 to your computer and use it in GitHub Desktop.
[cmdletbinding()]
param(
[Parameter(Mandatory)]
[Alias('ComputerName')]
[string[]]$InputObject,
[Parameter()]
[int16]$Port = 16992,
[Parameter(Mandatory)]
[System.Management.Automation.PSCredential]$Credential,
[Parameter()]
[System.Management.Automation.Runspaces.AuthenticationMechanism] $Authentication = [System.Management.Automation.Runspaces.AuthenticationMechanism]::Digest,
[Parameter()]
[ValidateRange(0,255)]
[int16]$SessionTimeout = 0,
[Parameter()]
[bool]$Is5900PortEnabled = $true,
[Parameter()]
[bool]$OptInPolicy = $false
)
BEGIN {}
PROCESS {
foreach ($ComputerName in $InputObject) {
$WsManServer = @{
ComputerName = $ComputerName
Port = $Port
Credential = $Credential
Authentication = $Authentication.ToString()
}
$IntelSchemaBase = 'http://intel.com/wbem/wscim/1/ips-schema/1/'
Test-WSMan @WsManServer -ErrorAction Stop | Out-Null
Write-Verbose "Testing if KVM is enabled in BIOS"
$Properties = $WsManServer + @{
ResourceUri = $IntelSchemaBase + 'IPS_KVMRedirectionSettingData'
}
$CurrentSettings = Get-WSManInstance @Properties
if ($CurrentSettings.EnabledByMEBx -ne 'true') {
Write-Error "The KVM feature is disabled by the BIOS's MEBx settings, it cannot be enabled remotely." -ErrorAction Stop
}
Write-Verbose "Configuraing KVM Redirection"
$Properties = $WsManServer + @{
ResourceUri = $IntelSchemaBase + 'IPS_KVMRedirectionSettingData'
ValueSet = @{
RFBPassword = $Credential.GetNetworkCredential().Password
Is5900PortEnabled = $Is5900PortEnabled.ToString().ToLower()
OptInPolicy = $OptInPolicy.ToString().ToLower()
SessionTimeout = $SessionTimeout.ToString()
}
}
Set-WSManInstance @Properties -ErrorAction Stop | Out-Null
Write-Verbose "Enabling KVM Redirection"
$Properties = $WsManServer + @{
Action = 'RequestStateChange'
ResourceUri = 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_KVMRedirectionSAP'
ValueSet = @{RequestedState = '2'}
}
Invoke-WSManAction @Properties | Out-Null
Write-Verbose "Current Settings:"
$Properties = $WsManServer + @{
ResourceUri = $IntelSchemaBase + 'IPS_KVMRedirectionSettingData'
}
Get-WSManInstance @Properties
}
}
END {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment