2

这似乎无法正常工作

我有以下脚本资源。

 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: 路径,因为 Import-Module RemoteDesktopServices 无法正常工作。也就是说,在失败的正上方,我看到来自 Import-Module RemoteDesktopServices 的详细日志记录正在发生。

如果我更改我的脚本资源,以便 SetScript、GetScript 和 TestScript 都将 powershell 作为一个新进程调用,它就可以工作。

powershell -NoProfile -ExecutionPolicy Bypass -Command "$using:commandStoredAsAString"

如果我使用 Invoke-Command 或 Invoke-Expression,它会爆炸,所以似乎运行一个单独的进程是关键。有没有办法让脚本资源在没有这种黑客攻击的情况下正常工作,或者它们只是无用/实施不善?

4

1 回答 1

2

问题出在 TestScript 中,它试图获取 'Get-ChildItem 'GatewayServer/RAP''。Import-Module RemoteDesktopServices 工作正常。如果要检查 gatewayServer\RAP 是否存在,请将 TestScript implementation 更改为 (Test-Path RDS:GatewayServer\RAP)。脚本 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 结果 = "" }

        }
        TestScript = {
            Import-Module RemoteDesktopServices
            return (Test-Path RDS:GatewayServer\RAP)
        }
    }
于 2016-04-14T22:35:24.843 回答