Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a Powershell DSC script locally

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
like image 412
Kye Avatar asked Sep 13 '16 01:09

Kye


People also ask

How do I run DSC configuration?

For a DSC configuration to be applied to a node, it must first be compiled into a MOF file. Running the configuration, like a function, will compile one . mof file for every Node defined by the Node block. In order to run the configuration, you need to dot source your HelloWorld.

How does DSC work in PowerShell?

Desired State Configuration (DSC) is a feature in PowerShell 4.0 and above that helps administrators to automate the configuration of Windows and Linux operating systems (OSes). DSC provides a set of PowerShell language extensions, cmdlets and a process called declarative scripting.

What PowerShell command is used to enact as a DSC?

There are two ways to enact PowerShell Desired State Configuration (DSC) configurations: push mode and pull mode.

Is PowerShell DSC free?

For Windows folks, there is a free and Windows-centric option available; PowerShell Desired State Configuration (DSC).


2 Answers

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
like image 67
N.Gupta Avatar answered Sep 28 '22 00:09

N.Gupta


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
like image 21
joshduffney Avatar answered Sep 28 '22 00:09

joshduffney