2016-09-13 70 views
1

我試圖在本地運行一個非常簡單的Powershell DSC腳本。 (我從來沒有計劃在這個階段拉或推配置文件)如何在本地運行Powershell DSC腳本

我收到以下錯誤消息。 WS-Management服務正在運行,但沒有防火牆漏洞或端口保留(服務器恰好是一個web服務器)...有沒有反正我可以允許這個服務器只接受本地請求?

The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". + CategoryInfo : ConnectionError: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : HRESULT 0x80338012 + PSComputerName : localhost

configuration SampleIISInstall 
    { 
     Node 127.0.0.1 
     { 
      File FileDemo { 
      Type = 'Directory' 
      DestinationPath = 'C:\TestUser3' 
      Ensure = "Present" 
     } 
     } 
    } 

    # Compile the configuration file to a MOF format 
    SampleIISInstall 

    # Run the configuration on localhost 
    Start-DscConfiguration -Path .\SampleIISInstall -Wait -Force -Verbose 

回答

3

嘗試:

 
configuration SampleIISInstall 
    { 
     Node "localhost" 
     { 
      File FileDemo { 
      Type = 'Directory' 
      DestinationPath = 'C:\TestUser3' 
      Ensure = "Present" 
     } 
     } 
    } 

    # Compile the configuration file to a MOF format 
    SampleIISInstall 

    # Run the configuration on localhost 
    Start-DscConfiguration -Path .\SampleIISInstall -Wait -Force -Verbose 
2

由於DSC使用PowerShell遠程你不能爲你指定的計算機名稱節點名稱使用的IP地址。使用localhost或$ env:computername應該可以工作,也可以完全刪除節點塊,只需在沒有它的情況下寫入DSC配置。

configuration SampleIISInstall 
    { 
      File FileDemo { 
      Type = 'Directory' 
      DestinationPath = 'C:\TestUser3' 
      Ensure = "Present" 
     } 
     } 

    # Compile the configuration file to a MOF format 
    SampleIISInstall 

    # Run the configuration on localhost 
    Start-DscConfiguration -Path .\SampleIISInstall -Wait -Force -Verbose