2016-09-13 30 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