Author Posts

August 23, 2016 at 8:10 pm

Hello, I've been banging my head on this stuff for a while, so lets imagine I have a resource:

Configuration WebProxy
{     
Param (
    [Parameter(Mandatory=$true)][string] $url
    )
Import-DscResource -Module nx
Node webproxy {  
        nxFile ProxyConf 
        {
            SourcePath = "$url_variable_goes_here"
            DestinationPath = '/etc/nginx/sites-available/proxy'
        }  
    }
}

So, I figured I could use configdata, but that's not convinient, I'd like to be able to pass value from pipeline at mof compile time, is that possible?

August 24, 2016 at 10:45 am

Hi there,

Should be more than possible, inside the configuration block its just standard powershell, of course the data you pass in will need to be a property on the DSC resource, but inside the config block you can run any standard powershell code, and this will be executed at compile time when you generate the mof.

Say in theory, you created a function that would obtain the source path URL variable, you could execute the function inside the configuration block, store that in a variable and pass it in. All this logic would be executed at the MOF compile time and be deserialized into the MOF format.


Configuration WebProxy
{     
Param (
    [Parameter(Mandatory=$true)][string] $url
    )
Import-DscResource -Module nx

$url = Get-SourcePathUrl

Node webproxy {  
        nxFile ProxyConf 
        {
            SourcePath =  $url
            DestinationPath = '/etc/nginx/sites-available/proxy'
        }  
    }
}

August 24, 2016 at 5:44 pm

Well, turns out you can just use "text" + $var + "text", who knew. Thanks!