PowerShell DSC脚本资源失败
这似乎不能正常工作 我有以下脚本资源PowerShell DSC脚本资源失败,powershell,dsc,powershell-5.0,Powershell,Dsc,Powershell 5.0,这似乎不能正常工作 我有以下脚本资源 Script RDGatewayCreateRAP { SetScript = { $localhost = $using:localhost $forest = $using:forest Import-Module RemoteDesktopServices Ne
Script RDGatewayCreateRAP
{
SetScript = {
$localhost = $using:localhost
$forest = $using:forest
Import-Module RemoteDesktopServices
New-Item -Path 'RDS:/GatewayServer/RAP' -Name 'RAP' -UserGroups "Domain Users@$forest" -ComputerGroupType 1 -ComputerGroup "Domain Computers@$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
这可能是因为找不到RDS:path,因为导入模块RemoteDesktopServices工作不正常。也就是说,在故障的正上方,我看到了来自导入模块RemoteDesktopServices的详细日志记录
如果我更改脚本资源,使SetScript、GetScript和TestScript都作为一个新进程调用powershell,它就会工作
powershell -NoProfile -ExecutionPolicy Bypass -Command "$using:commandStoredAsAString"
如果我使用Invoke命令或Invoke表达式,它会崩溃,因此运行一个单独的进程似乎是关键。有没有一种方法可以使脚本资源在没有这种黑客攻击的情况下正常工作,或者它们只是无用的/实现得不好?问题在于TestScript中试图获取“get ChildItem”GatewayServer/RAP“”。导入模块RemoteDesktopServices工作正常。 如果要检查是否存在gatewayServer\RAP,请将TestScript实现更改为(测试路径RDS:gatewayServer\RAP)。 脚本RDGatewayCreateRAP { SetScript={ $localhost=$using:localhost $forest=$using:forest 导入模块RemoteDesktopServices
#新项目-路径“RDS:/GatewayServer/RAP”-名称“RAP”-用户组“域用户@$forest”-计算机组类型1-计算机组“域计算机@$forest” } GetScript={ 返回@{ GetScript=$GetScript SetScript=$SetScript TestScript=$TestScript Result=“” }
}
TestScript = {
Import-Module RemoteDesktopServices
return (Test-Path RDS:GatewayServer\RAP)
}
}