question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Applying DSC Config from Powershell Core on Windows

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
SteveL-MSFTcommented, Jun 20, 2019

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.

1reaction
mwrockcommented, Aug 2, 2017

Done @iSazonov

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found