這似乎無法正常工作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"
}
使用啓動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
這大概是因爲RDS:路徑沒有找到,因爲導入模塊RemoteDesktopServices無法正常工作。也就是說,在發生故障之前,我會看到來自Import-Module RemoteDesktopServices的詳細日誌記錄。
如果我更改我的腳本資源,所以SetScript,GetScript和TestScript都將PowerShell作爲一個新進程調用,它可以工作。
powershell -NoProfile -ExecutionPolicy Bypass -Command "$using:commandStoredAsAString"
如果我使用Invoke-Command或Invoke-表達,它吹起來,所以它似乎是運行一個單獨的進程是關鍵。有沒有一種方法可以讓腳本資源在沒有這種黑客攻擊的情況下正常工作,還是僅僅是沒有用處/執行不力?