Powershell: Applying DSC Config from Powershell Core on Windows

Created on 1 Aug 2017  路  6Comments  路  Source: PowerShell/PowerShell

I've been playing with various techniques of using powershell core to apply IIS configuration on windows (I have a specific use case for this). Since the IISAdministration and WebAdministration modules are not .net core compliant, I dropped to appcmd.exe but its awkward to say the least. It occurred to me that better than all of the above would be to use DSC. The challenge is that Powershell core lacks Invoke-DSCResource and Start-DSCConfiguration. So I call the LCM via Invoke-CimMethod like so:

Install-Module xWebAdministration -Force

. (Join-Path my_configs website.ps1)

# NewWebsite is in the sourced config above
$mof = NewWebsite -OutputPath "{{pkg.svc_path}}"
$configurationData = Get-Content $mof.FullName -Encoding Byte -ReadCount 0
$totalSize = [System.BitConverter]::GetBytes($configurationData.Length + 4)
$configurationData = $totalSize + $configurationData

# Need to move xWebAdministration because LCM is not honoring PS Core's PSModulePath
$mod = (Get-Module xWebAdministration -ListAvailable).ModuleBase
$machine_mod = "C:\Program Files\windowsPowerShell\Modules\xWebAdministration"
if(Test-Path $machine_mod) { Remove-Item $machine_mod -Recurse -Force }
Move-Item $mod $machine_mod -Force

Invoke-CimMethod -ComputerName localhost -Namespace "root/Microsoft/Windows/DesiredStateConfiguration" -ClassName "MSFT_DSCLocalConfigurationManager" -MethodName "SendConfigurationApply" -Arguments @{ConfigurationData = $configurationData; Force = $true}

This works but still has some obvious awkwardness to it.

I've searched around and did not see how I could apply DSC configuration completely in PS Core without breaking out the WMI but I may easily have missed something. Is there a better way?

Area-DSC Issue-Question Resolution-Answered

Most helpful comment

The main problem with IIS is that the namespace needed to administer IIS isn't part of .NET Core and no plans to support it in .NET Core. Alternatively, we're working on a WinPS bridge in PS7 timeframe that may resolve this. I'm referring specifically to the cmdlet and not the DSC Resource. Some fixes have come to the DSC module in PS7 from DSC team so applying DSC config in general should work. Since LCM 1.0 is using Windows PowerShell, this might just work with PS7 Preview.2.

All 6 comments

@mwrock Could you please report incompatibility modules in #4062 ?

Done @iSazonov

Hi guys, is there any update on how to manage IIS using Powershell Core?

The latest information was that IIS team has no plans to support PowerShell Core. Perhaps the situation changed after the PowerShell team announced that version 7 should be an almost complete replacement for Windows PowerShell. /cc @SteveL-MSFT
In any case it is better ask IIS team. You could use Windows 10 Feedback utility, UserVoice, Microsoft forums and others.

The main problem with IIS is that the namespace needed to administer IIS isn't part of .NET Core and no plans to support it in .NET Core. Alternatively, we're working on a WinPS bridge in PS7 timeframe that may resolve this. I'm referring specifically to the cmdlet and not the DSC Resource. Some fixes have come to the DSC module in PS7 from DSC team so applying DSC config in general should work. Since LCM 1.0 is using Windows PowerShell, this might just work with PS7 Preview.2.

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Was this page helpful?
0 / 5 - 0 ratings