PowerShell DSC - how to pass configuration parameters to ScriptResources? -


I have a lot of trouble getting PowerShell's desired State Configuration script to work in order to configure in-house applications The root of the problem is that I can not pass my configuration data in a ScriptResource (at least in the way I'm trying to do this).

My script is about to create a config folder for our in-house application, and then write some settings in a file:

  Configuration MyApp {param ([string []] $ ComputerName = $ env: ComputerName) node $ ComputerName {file configuration folder {type = "directory" destination path = $ node. Confirm Folder = "Current"} Script Configuration File {SetScript = {Write-Verbose "Configuration File Setting Scripts On"); Write-verbose "folder = $ ($ node .config folder)"; Write-verbose "file name = $ ($ node .configfile)"; [System.IO.File] :: WriteAllText ($ node .confiff file, "enabled =" + $ node. Enabled); } TestScript = {write-verbose "Running ConfigurationFile.TestScript"; Write-verbose "folder = $ ($ node .config folder)"; Write-verbose "file name = $ ($ node .configfile)"; Return (test-path $ node .config file); } GetScript = {@ {Configure = (test-path $ node .configfile)}} DependsOn = "[file] configuration folder"}}}  

For reference, my configuration data look like this Is:

  $ config = @ {NodeName = @ (@ {NodeName = "*" ConfigFolder = "C: \ myapp \ config" ConfigFile = "C: \ myapp \ config \ config. Txt "} @ {NodeName =" ServerA "enabled =" true "} @ {NodeName =" ServerB "enabled =" wrong "}}}  

And I do a DSC application with the following I am:

  $ mof = MyApp - Configuration data $ config; Start-DSC Configuration MyApp-Wait - Verbose;  

When I apply this configuration, it happily creates a folder, but fails to do anything from the config file, given the output given below, it is clear that $ Node variable is zero inside ConfigurationFile / TestScript, but I do not know how to reference it from within that block.

  lcm: [start] [[script] configuration file] lcm: [initial test] [[script] configuration file] [[script] configuration file] configuration file. Script [[script] configuration file] node is empty = true [[script] configurationfile] folder = [[script] configuration file] file name = lcm: [and test] [[script] configuration file] in 0.4850 seconds  

I have burned all day searching for this specific problem online, but use all file and registry resources or other non-script resources in all the examples of variables, parameters and configuration data Is done, which has already worked in the "configurationfolder" block in my script, on what I am stuck on, from within a script resource such as my "config file" How to reference the configuration data.

I have drawn a complete blank so any help would be greatly appreciated if everything fails, then I may have to create a separate "configuration" script per server and hard-code value, which is actually I probably do not want to.

Cheers,

Mike

The time is present when the MOF files are compiled, not the runtime DSC engine implements your scripts Script script's SetScript, GetScript, and TestScript attributes are actually string, script blocks are not.

It is possible to generate those script strings (all required data is already expanded from your configuration data), but you

I have posted a brief example of this over on the original teknote thread


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -