Это не работает должным образомРесурсы сценария PowerShell DSC Сбой
У меня есть следующий ресурс сценария.
Script RDGatewayCreateRAP
{
SetScript = {
$localhost = $using:localhost
$forest = $using:forest
Import-Module RemoteDesktopServices
New-Item -Path 'RDS:/GatewayServer/RAP' -Name 'RAP' -UserGroups "Domain [email protected]$forest" -ComputerGroupType 1 -ComputerGroup "Domain [email protected]$forest"
}
GetScript = {
return @{
GetScript = $GetScript
SetScript = $SetScript
TestScript = $TestScript
Result = ""
}
}
TestScript = {
Import-Module RemoteDesktopServices
return [boolean](Get-ChildItem 'GatewayServer/RAP')
}
DependsOn = "[Script]RDDeploymentGatewayConfiguration"
}
Использование Start-DscConfiguration -wait -Verbose для конфигурации с помощью этого сценария, то его ошибки при
VERBOSE: [WIN-EEK1CL8BED9]: [[Script]RDGatewayCreateRAP::[cRdsServer]RdsServer] Importing cmdlet '
Convert-License'.
Cannot find path 'C:\Windows\system32\GatewayServer\RAP' because it does not exist.
+ CategoryInfo : ObjectNotFound: (C:\Windows\system32\GatewayServer\RAP:) [], CimException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : localhost
Предположительно это происходит потому, что РДС: путь не найден, поскольку Import-Module RemoteDesktopServices работает неправильно. Тем не менее, сразу же после сбоя, я вижу подробное ведение журнала из Import-Module RemoteDesktopServices.
Если я изменю свой ресурс скрипта, так что SetScript, GetScript и TestScript все вызовут powershell как новый процесс, он работает.
powershell -NoProfile -ExecutionPolicy Bypass -Command "$using:commandStoredAsAString"
Если я использую Invoke-Command или Invoke-Expression, она взрывается, так что кажется, как работает отдельный процесс является ключевым. Есть ли способ заставить ресурсы Script правильно работать без такого взлома или они просто бесполезны/плохо реализованы?