Run DSC Script placed on a server using PowerShell_Script

I would like to keep my DSC code in .ps1 itself and use PowerShell_Script to in receipe.rb to execute it.

Is this possible?

A simple Powershell (non-dsc) file execution is working fine but I haven't able to execute DSC Ps1 script.

powershell_script "BlobCacheSettings" do
code "E:/Tasks/Set-SPBlobCacheSettings.ps1" - This is DSC Script
end

Hi @sgandewar

We'll need to see the code for Set-SPBlobCacheSettings.ps1 to be sure - but what you describe should be achievable. DSC may not be monitoring for configuration changes. You can check this in PowerShell using (Get-DscLocalConfigurationManager | select -ExpandProperty "ConfigurationMode") - if the output is ApplyOnly then you need to trigger the LCM manually.

Scripts that need to trigger the LCM manually usually have something like this at the bottom of them:

MyConfiguration -OutputPath <path>
Set-DscLocalConfigurationManager -Path <path> 

HTH
Stuart

Can you please post complete example of the DSC script with these 2 lines if you have handy?

Well I'm sorry but it looks like I gave you the wrong cmdlet to run, it should of course have been Start-DscConfiguration (unless you are configuring the LCM)

Here's a complete example:

Configuration DemoResource
{
    Import-DscResource -ModuleName "PSDesiredStateConfiguration"
    Node $env:COMPUTERNAME
    {
        File Test
        {
          Type = "File"
          DestinationPath = "$env:TEMP\test.txt"
          Ensure = "Present"
          Contents = "Hello, DSC!"
        }
    }
}

DemoResource -OutputPath $env:TEMP\mof\
Start-DscConfiguration -Path $env:TEMP\mof\ -Wait

Stuart

Thanks! This worked like a charm.