Applying DSC Config from Powershell Core on Windows
See original GitHub issueI’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?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Get started with Desired State Configuration (DSC) for ...
This topic explains how to get started using PowerShell Desired State Configuration (DSC) for Windows.
Read more >PowerShell Desired State Configuration: The Basics
'Desired State Configuration (DSC) is an essential part of the configuration, management and maintenance of Windows-based servers.
Read more >Applying basic system configuration using PowerShell DSC
Applying basic system configuration using PowerShell DSC ... us to configure Windows or Linux Infrastructure using configuration as a code.
Read more >The Basics of PowerShell DSC (Desired State Configuration)
Desired State Configuration (DSC) allows you to configure Windows and applications using a configuration file and PowerShell DSC resource ...
Read more >PowerShell DSC (Desired State Configuration)
DSC (Desired State Configuration) is a PowerShell management platform that uses Configuration as code (CaC) declarations, in GitHub. On every ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Done @iSazonov