Skip to content

Using the Script resource in configurations that use SharePointDsc

Brian Farnhill edited this page Apr 11, 2017 · 3 revisions

In some circumstances you may find yourself needing to use a Script resource to be able to perform a function that is not included in SharePointDsc. If your script resource needs to add the SharePoint snap-in you may find that this will cause issues with other resources provided by SharePointDsc (as discussed in in this issue). To work around this, it is recommended that instead of loading the snap-in yourself you use the Invoke-SPDscCommand helper to achieve this. This helper method will load the snap-in for you in the same way that the native resources of SharePointDsc do, and will avoid conflicts with it being loaded multiple times.

An example of this in a script resources is shown below:

Script SPDscExample
{
    GetScript = {
        Invoke-SPDscCommand -ScriptBlock {
            # Your code goes here
        }
    }
    ...
}

If you need to pass a credential or additional arguments, you can use the -Credential and -Arguments parameters for these purposes also.

Clone this wiki locally