Benutzer:MovGP0/Powershell/DSC/Configuration

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      

DSC Configuration

[Bearbeiten | Quelltext bearbeiten]
MyConfiguration.ps1
Configuration MyConfiguration 
{
    # Import-DSCResource is a keyword and not a PS-command
    Import-DSCResource -Module @('WindowsFeature','File','RemoteRegistry')

    Node Computername {
        WindowsFeature Backup {
            Name="Windows-Server-Backup"
            Ensure="Present"
        }
        File Development {
            Type="Directory"
            Ensure="Present"
            DestinationPath="C:\Development"
        }
        Service RemoteRegistry {
            Name="RemoteRegistry", 
            Startup="Automatic"
            State="Running"
        }
    }

    Node @("Server1", "Server2") {
        # ...
    }
}
Execute
# Load configuration 
. .\MyConfiguration.ps1
# Create MOF file
MyConfiguration
# Execute configuration on computer
Start-DscConfiguration -Path .\MyConfiguration
MyConfiguration.psd1
Configuration MyConfiguration 
{
    Param(
        [string[]]$Computername,
        [string[]]$Services
    )

    Node @($Computername) {
        # ...
    }

    foreach ($computer in $Computername){
        # ...
    }
}

ConfigurationData

[Bearbeiten | Quelltext bearbeiten]
MyConfiguration.psd1
$ConfigurationData = @{
    AllNodes = @( # required key
        @{NodeName = "FP-123"; Role = "FilePrint"}, 
        @{NodeName = "WS-421"; Role = "WebServer"}, 
        @{NodeName = "*"; Features = "Windows-Server-Backup","PowerShell-V4"}
    );
    MyData = @{ # optional arbitrarily named key
        MyData = Import-CSV "C:\Development\Translations.csv"
    }
}
MyConfiguration.ps1
Configuration MyConfiguration 
{
    Node $AllNodes.Nodename {
        $Node.features.foreach({
            WindowsFeature $_ { 
                Name = $_
                Ensure = "Present"
            }
        })

        Service RemoteRegistry {
            Name = "RemoteRegistry", 
            StartupType = "Automatic"
            State = "Running"
        }
    }
}
Create/Validate MOF
. .\MyConfig\MyConfig.ps1
MyConfiguration -ConfigurationData .\MyConfig\MyConfiguration.psd1 -OutputPath .