@ü.li:Listing 1: Softwareverteilung mit DSC @li:$Quellpfad = "\\Server123\Software\Setup_for_HelloWorld_VBNET.msi" configuration HelloWorldInstallieren { Import-DscResource –ModuleName 'PSDesiredStateConfiguration' node $AllNodes.NodeName.Where{$_.StartsWith('D')} { Log Protokolleintrag1 { Message = "Hello World wird installiert: $(Get-Date)" } File SetupKopieren { Ensure = "Present" SourcePath = $Quellpfad DestinationPath = "C:\temp\helloworld\" Recurse = $true Type = "File" DependsOn="[Log]Protokolleintrag1" } Package HelloWorldInstallieren { Ensure = "Present" Path = "C:\temp\helloworld\Setup_for_HelloWorld_VBNET.msi" Name = "Hello World VB.NET" ProductId = "29E4EB91-7F2C-4B27-9FF5-DBE35A0F69AF" DependsOn="[File]SetupKopieren" } File SetupDirLoeschen { Ensure = "Absent" DestinationPath = "C:\temp\helloworld" Recurse = $true Force=$true Type = "Directory" DependsOn="[Package]HelloWorldInstallieren" } Log Protokolleintrag2 { Message = "Hello World installiert!" DependsOn="[Package]HelloWorldInstallieren" } Registry RegEintrag1Erzeugen { Ensure ="Present" Key ="HKEY_LOCAL_MACHINE\SOFTWARE\$($ConfigurationData.Firma)" ValueName="Angelegt am" ValueData=$(Get-date) DependsOn="[Package]HelloWorldInstallieren" } Registry RegEintrag2Erzeugen { Ensure ="Present" Key ="HKEY_LOCAL_MACHINE\SOFTWARE\$($ConfigurationData.Firma)" ValueName="Rechneraufgabe" ValueData=$($Node.Aufgabe) DependsOn="[Package]HelloWorldInstallieren" } } } @ü.li:Listing 2: Kompilieren und Starten einer DSC-Konfiguration @li:"Lade DSC-Dokument..." d:\Konfigurationen\DSC_Dokument.ps1 $Konfiguration = @{ # Eingabedaten Firma = "www.IT-Visions.de"; # Rechnerliste AllNodes = @( @{ NodeName="D130"; Aufgabe ="Arbeitsplatz 1. Etage" } @{ NodeName="D140" Aufgabe ="Arbeitsplatz 2. Etage" } @{ NodeName="Server103" Aufgabe ="Fileserver" } @{ NodeName="Server108" Aufgabe ="DC" } ) } "DSC wird kompiliert..." HelloWorldInstallieren -ConfigurationData $Konfiguration -OutputPath c:\temp\softwareinstallation.mof "DSC wird ausgeführt..." Start-DscConfiguration c:\temp\softwareinstallation.mof -verbose -wait -force "Validierung des Beispiels mit PowerShell-Commandlets" invoke-command -ComputerName d140,d130 -scriptblock { ` [System.Environment]::machinename get-item HKLM:\SOFTWARE\www.IT-Visions.de | ft } @ü.li:Listing 3: Ausschnitt aus der MOF-Datei (Mischung aus Listing 1 und 2) @li:/* @TargetNode='D130' @GeneratedBy=HS @GenerationDate=01/21/2016 17:56:29 @GenerationHost=E60 */ instance of MSFT_LogResource as $MSFT_LogResource1ref { Message = "Hello World wird installiert: 01/21/2016 17:56:28"; SourceInfo = "T:\\DSC\\DSC_SoftwareInstallieren_MehrereKnoten.ps1::14::9::Log"; ResourceID = "[Log]Protokolleintrag1"; ModuleName = "PSDesiredStateConfiguration"; ModuleVersion = "0.0"; ConfigurationName = "HelloWorldInstallieren"; }; ... @ü.li:Listing 4: Einsatz der Script-Ressource (Registry-Key entfernen) @li:configuration DSCErstesBeispielMitParametern { node $AllNodes.NodeName { Script SchluesselLoeschen { TestScript = { -not (Test-Path "hklm:SOFTWARE\www.IT-Visions.de") } SetScript = { Remove-Item "hklm:SOFTWARE\www.IT-Visions.de" } GetScript = { @{result = "Schlüssel vorhanden: " + (Test-Path "hklm:SOFTWARE\www.IT-Visions.de")} } } } } $ConfigurationData = @{ AllNodes = @( @{ NodeName="D130" } @{ NodeName="D140" } ) } "DSC ist geladen!" DSCErstesBeispielMitParametern -ConfigurationData $configurationData "DSC ist kompiliert" Start-DscConfiguration DSCErstesBeispielMitParametern -verbose -wait -force @ü.li:Listing 5: DSC-Dokument für einen Linux-Benutzer @li:Configuration CentOS_Benutzer { Import-DSCResource -Module nx Node $LinuxServer.ComputerName { nxUser BenutzerAnlage{ UserName = "thomasw" Description = "PowerShell-Trainer" Password = 'Aspphpxml123' Ensure = "Present" HomeDirectory = "/home/thomasw" }} } @ü.li:Listing 6: Linux-Benutzer anlegen @li:CentOS_Benutzer -OutputPath d:\LinuxCon g\ | Out-Null $Cred = Get-Credential -Username:"root" -Message:"Bitte root verwenden" $Opt = New-CimSessionOption -UseSSL:$True -SkipCACheck:$True -SkipCNCheck:$True -SkipRevocationCheck:$True $LinuxServer = New-CimSession -Credential:$Cred -ComputerName:CentOS123 -Port:5986 -Authentication:Basic -SessionOption:$Opt Start-DscConfiguration -CimSession:$LinuxServer -Path:"d:\LinuxCofig" -Verbose -Wait