I received a message from the PowerShell Gallery script analyzer (PSScriptAnalyzer) that the DSC Configuration scripts I posted contain an error regarding loading xPSDesiredStateConfiguration (error below, same error for all 4 Configuration Scripts).
While I'm not entirely sure, it appears to me that the issue is due to the host running the script analyzer not having the module loaded in it's $env:PSModulePath- I can run all of my own DSC Configuration Scripts on a Windows 10 development VM that has xPSDesiredStateConfiguration so I never encountered this issue in development.
I'd really like to do what I can to resolve this so I am trying to figure out if I can correct this on my end or if I just have no control over what modules the analyzer's host has loaded. Please note that xPSDesiredStateConfiguration is the same module being loaded by xChrome and xFirefox, both currently on the gallery.
The lines that are triggering the script analyzer to return this error are:
Import-DscResource -ModuleName xPSDesiredStateConfiguration
as well as a call to xRemoteFile which is part of xPSDesiredStateConfiguration
ERROR: Invoke-ScriptAnalyzer : Parse error in file
A lot of people run into this, and it seems to be an artifact of the Analyzer. I suspect you're correct in that it's the module not existing locally – Analyzer isn't reaching out to a target machine.
Don, I heard back from another member of the Config Admin team after I responded to a message from the Script Analyzer-
As it turns out, PSScriptAnalyzer purposely does not load modules (like xPSDesiredStateConfiguration) unless they are explicitly mentioned as one of the RequiredModules in the module manifest. Even if a script explicitly makes a call to Import-Module, the module still needs to be listed in the RequiredModules array in the corresponding module manifest.
For anyone else running into this, the solution is to make sure that the following line exists in all module manifests that need Resources from xPSDesiredStateConfiguration:
RequiredModules = @('xPSDesiredStateConfiguration')
If you are loading more than one external module, add an extra array element for each other module that you need. Note that you don't ever need to include PSDesiredStateConfiguration (non-X) and in fact Publish-Module will return an error if you do try to.
You must be logged in to reply to this topic.