xRemoteDesktopSessionHost
xRemoteDesktopSessionHost copied to clipboard
xRDServer: Adding RDS-Web-Access role throws exception
Details of the scenario you tried and the problem that is occurring
Using xRDServer ressource to add an RDS-Web-Access server raises exceptions but works anyway.
Verbose logs showing the problem
{
"Exception": {
"Message": "The PowerShell DSC resource \u0027[xRDServer]AddWebServer02\u0027 with SourceInfo \u0027::179::9::xRDServer\u0027 threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.",
"Data": {
},
"InnerException": {
"SerializedRemoteException": "System.Management.Automation.CommandNotFoundException: The term \u0027Get-RDWorkspace\u0027 is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.\r\n at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)\r\n at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)\r\n at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)\r\n at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)\r\n at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)\r\n at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)\r\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\r\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)",
"SerializedRemoteInvocationInfo": "System.Management.Automation.InvocationInfo",
"ErrorRecord": "The term \u0027Get-RDWorkspace\u0027 is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.",
"WasThrownFromThrowStatement": false,
"Message": "The term \u0027Get-RDWorkspace\u0027 is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.",
"Data": "System.Collections.ListDictionaryInternal",
"InnerException": null,
"TargetSite": null,
"StackTrace": null,
"HelpLink": null,
"Source": null,
"HResult": -2146233087
},
"TargetSite": null,
"StackTrace": null,
"HelpLink": null,
"Source": null,
"HResult": -2146233079
},
"TargetObject": null,
"CategoryInfo": {
"Category": 7,
"Activity": "",
"Reason": "InvalidOperationException",
"TargetName": "",
"TargetType": ""
},
"FullyQualifiedErrorId": "NonTerminatingErrorFromProvider",
"ErrorDetails": null,
"InvocationInfo": null,
"ScriptStackTrace": null,
"PipelineIterationInfo": [
]
}
Suggested solution to the issue
I found a workaround by adding a reboot if Add-RDServer fails. This is not a ideal solution as it could result in an infinite loop, but it does the job for me right now.
xRDSessionDeployment RDDeployment
{
ConnectionBroker = $MainConnectionBroker
WebAccessServer = $WebAccessServer1
SessionHost = $SessionHost
PsDscRunAsCredential = $AdminCreds
DependsOn = "[xDSCDomainjoin]JoinDomain"
}
Script AddWebServer02 {
GetScript = { @{} } # not used
SetScript = {
try {
Import-Module RemoteDesktop
Add-RDServer -Server $Using:WebAccessServer2 -Role 'RDS-Web-Access' -ConnectionBroker $Using:ConnectionBroker
}
catch {
# The function throws an exception but still works
}
}
TestScript = {
Import-Module RemoteDesktop
$servers = Get-RDServer -Role 'RDS-Web-Access' -ConnectionBroker $Using:MainConnectionBroker -ErrorAction SilentlyContinue
if ($servers -and $Using:WebAccessServer2 -in $servers.Server) { return $true } else { return $false }
}
PsDscRunAsCredential = $AdminCreds
DependsOn = "[xRDSessionDeployment]RDDeployment"
}
The DSC configuration that is used to reproduce the issue (as detailed as possible)
xRDSessionDeployment RDDeployment
{
ConnectionBroker = $MainConnectionBroker
WebAccessServer = $WebAccessServer1
SessionHost = $SessionHost
PsDscRunAsCredential = $AdminCreds
DependsOn = "[xDSCDomainjoin]JoinDomain"
}
xRDServer AddWebServer02
{
ConnectionBroker = $MainConnectionBroker
Role = 'RDS-Web-Access'
Server = $WebAccessServer2
PsDscRunAsCredential = $AdminCreds
DependsOn = "[xRDServer]AddGateway02"
}
The operating system the target node is running
OsName : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture : 64-bit
WindowsVersion : 1809
WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage : en-US
OsMuiLanguages : {en-US}
Version and build of PowerShell the target node is running
Name Value
---- -----
PSVersion 5.1.17763.1852
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1852
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Version of the DSC module that was used
2.0.0