Aan de slag met Desired State Configuration (DSC) voor Windows
In dit onderwerp wordt uitgelegd hoe u aan de slag gaat met PowerShell Desired State Configuration (DSC) voor Windows. Zie voor algemene informatie over DSC Aan de slag met Windows PowerShell Desired State Configuration.
Ondersteunde Windows besturingssysteemversies
De volgende versies worden ondersteund:
- Windows Server 2022
- Windows Server 2019
- Windows Server 2016
- Windows Server 2012R2
- Windows Server 2012
- Windows Server 2008 R2 SP1
- Windows 11
- Windows 10
- Windows 8.1
- Windows 7
De Microsoft Hyper-V Server zelfstandige product-SKU bevat geen implementatie van Desired State Configuration zodat deze niet kan worden beheerd door PowerShell DSC of Azure Automation State Configuration.
DSC installeren
PowerShell Desired State Configuration is opgenomen in Windows en bijgewerkt via Windows Management Framework. De nieuwste versie is Windows Management Framework 5.1.
Notitie
U hoeft de functie DSC-Service Windows Server niet in te stellen om een machine te beheren met behulp van DSC. Deze functie is alleen nodig bij het bouwen van een Windows Pull Server-exemplaar.
DSC gebruiken voor Windows
In de volgende secties wordt uitgelegd hoe u DSC-configuraties kunt maken en uitvoeren op Windows computers.
Een MOF-configuratiedocument maken
Het Windows PowerShell Configuration sleutelwoord wordt gebruikt om een configuratie te maken.
In de volgende stappen wordt beschreven hoe u een configuratiedocument maakt met behulp Windows PowerShell.
Een module met DSC-resources installeren
Windows PowerShell Desired State Configuration bevat ingebouwde modules met DSC-resources. U kunt modules ook laden vanuit externe bronnen, zoals de PowerShell Gallery, met behulp van de PowerShellGet-cmdlets.
Install-Module 'PSDscResources' -Verbose
Een configuratie definiƫren en het configuratiedocument genereren
Configuration EnvironmentVariable_Path
{
param ()
Import-DscResource -ModuleName 'PSDscResources'
Node localhost
{
Environment CreatePathEnvironmentVariable
{
Name = 'TestPathEnvironmentVariable'
Value = 'TestValue'
Ensure = 'Present'
Path = $true
Target = @('Process', 'Machine')
}
}
}
EnvironmentVariable_Path -OutputPath:"./EnvironmentVariable_Path"
De configuratie toepassen op de machine
Notitie
Als u wilt dat DSC kan worden uitgevoerd, Windows geconfigureerd om externe PowerShell-opdrachten te ontvangen, zelfs wanneer u een configuratie localhost gebruikt. Als u uw omgeving eenvoudig op de juiste manier wilt configureren, kunt u deze Set-WsManQuickConfig -Force uitvoeren in een PowerShell-terminal met verhoogde bevoegdheid.
Configuratiedocumenten (MOF-bestanden) kunnen worden toegepast op de machine met behulp van de cmdlet Start-DscConfiguration.
Start-DscConfiguration -Path 'C:\EnvironmentVariable_Path' -Wait -Verbose
De huidige status van de configuratie op te halen
De cmdlet Get-DscConfiguration vraagt de huidige status van de machine op en retourneert de huidige waarden voor de configuratie.
Get-DscConfiguration
De cmdlet Get-DscLocalConfigurationManager retourneert de huidige metaconfiguratie die op de machine is toegepast.
Get-DscLocalConfigurationManager
De huidige configuratie van een computer verwijderen
Remove-DscConfigurationDocument
Remove-DscConfigurationDocument -Stage Current -Verbose
Instellingen configureren in lokale Configuration Manager
Pas een Meta Configuration MOF-bestand toe op de machine met behulp van de cmdlet Set-DSCLocalConfigurationManager. Vereist het pad naar metaconfiguratie MOF.
Set-DSCLocalConfigurationManager -Path 'c:\metaconfig\localhost.meta.mof' -Verbose
Windows PowerShell Desired State Configuration logboekbestanden maken
Logboeken voor DSC worden geschreven naar Windows gebeurtenislogboek in het pad Microsoft-Windows-Dsc/Operational .
Aanvullende logboeken voor het debuggen kunnen worden ingeschakeld door de stappen in Waar zijn DSC-gebeurtenislogboeken? te volgen.