How to run a Powershell DSC script locally
Asked Answered
K

2

7

I'm trying to run a very simple Powershell DSC script locally. (I never plan on pulling or pushing configuration files at this stage)

I get the following error message. The WS-Management service is running, but there are no firewall holes or ports reserved (server happens to be a webserver)... Is there anyway I can allow this server is only accept local requests?

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
Kagoshima answered 13/9, 2016 at 1:8 Comment(0)
B
6

Try:

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
Bruton answered 13/9, 2016 at 16:26 Comment(0)
V
4

Since DSC Uses PowerShell remoting you can't use IP addresses for the nodename you have to specify a computer name. Using localhost or $env:computername should work you could also remove the node block completely and just write the DSC config without it.

 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
Vitrify answered 14/9, 2016 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.