2016-04-13 7 views
2

Это не работает должным образомРесурсы сценария 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 правильно работать без такого взлома или они просто бесполезны/плохо реализованы?

ответ

2

Проблема в TestScript, где он пытается получить «Get-ChildItem» GatewayServer/RAP ». Импорт-модуль RemoteDesktopServices работает нормально. Если вы хотите проверить наличие замены версии TestScript для gatewayServer \ RAP (Test-Path RDS: GatewayServer \ RAP). Script RDGatewayCreateRAP { SetScript = { $ = $ локальный с помощью: локальный $ лес = $ с помощью: леса Import-Module RemoteDesktopServices
# New-Item 'RDS:/GatewayServer/RAP' -Path RAP -name» "-UserGroups "Пользователи домена @ $ лес" -ComputerGroupType 1 -ComputerGroup "Компьютеры домена @ $ лес" } GetScript = { возвращение @ { GetScript = $ GetScript SetScript = $ SetScript TestScript = $ TestScript Результат = "" }

 } 
     TestScript = { 
      Import-Module RemoteDesktopServices 
      return (Test-Path RDS:GatewayServer\RAP) 
     } 
    } 

 Смежные вопросы

  • Нет связанных вопросов^_^