I find that I am using this resource a lot in my configuration. I am wondering if I understand it completely.
I t appears that I have to re load my variables in the setscript and testscript sections in every script block.
.
It also appears that I have Import any modules that I am using in each block.
So 18 time for 18 web sites. I notice that the DSC configuration imports every cmdlet every time it runs, (18 times).
Am I missing a trick that would allow me to import the module just once? How about the variables?
Make them Global?
Still working on understanding the GetScript block.
I am using this rather than the xWebSite resource because it does not support setting the ID which is a requirement here.
Also, it does not support the net.tcp protocol.
One trick you can use with the script resource is to define your variables out in the configuration, and then use the $using scope modifier inside your blocks. As far as the MOF file goes, the end result is the same: DSC will inject those variables into the scripts for you, but it cleans up your code a bit.
You do probably need to leave the call to Import-Module there, at least in the Set script. If you were calling an actual cmdlet from the WebAdministration module (such as Get-Website in your test script), you could just let module auto-loading take care of it, but since you’re just using the IIS drive and the generic cmdlets, the explicit import is likely necessary.