Giter VIP home page Giter VIP logo

Comments (6)

raandree avatar raandree commented on June 2, 2024

@MichaelGrafnetter, can you send me the DSC configuration so that I can easily reproduce it?

from automatedlab.

MichaelGrafnetter avatar MichaelGrafnetter commented on June 2, 2024

@raandree Sure! I just hope that this will work for you, as I copied it from a much larger DSC config:

$script:labSources = 'C:\LabSources'
$script:vmPath = 'C:\LabVMs'
$script:labContent = 'C:\ADLab'
$script:labAdmin = 'Admin'
$script:adminPassword = 'Pa$$w0rd'

Configuration ADLab
{
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node 'localhost'
    {
        LocalConfigurationManager
        {
            ConfigurationModeFrequencyMins = 60
            RebootNodeIfNeeded = $true
            ConfigurationMode = 'ApplyAndAutoCorrect'
            ActionAfterReboot = 'ContinueConfiguration'
        }

        WindowsFeature HyperV
        {
            Name = 'Hyper-V'
            IncludeAllSubFeature = $true
            Ensure = 'Present'
        }

        Script LabDefinition
        {
            DependsOn = '[WindowsFeature]HyperV'
            TestScript = {
                $version = Get-Content -Path $using:labContent\ConfiguredVersion.txt -ErrorAction SilentlyContinue
                return (Get-Lab -List) -contains 'ADLab' -and $version -eq 13
            }
            SetScript = {
                $global:labSources = $using:labSources
                New-LabDefinition -Name ADLab -DefaultVirtualizationEngine HyperV -VmPath $using:vmPath
                Add-LabVirtualNetworkDefinition -Name ADLab -AddressSpace 10.213.0.0/24

                $defaultDomain = 'contoso.com'
                Add-LabDomainDefinition -Name $defaultDomain -AdminUser $using:labAdmin -AdminPassword $using:adminPassword
                Add-LabDomainDefinition -Name 'adatum.com' -AdminUser $using:labAdmin -AdminPassword $using:adminPassword
                Set-LabInstallationCredential -Username $using:labAdmin -Password $using:adminPassword

                $PSDefaultParameterValues = @{ 
                    'Add-LabMachineDefinition:OperatingSystem' = 'Windows Server 2022 Standard (Desktop Experience)'
                    'Add-LabMachineDefinition:DomainName' = $defaultDomain
                    'Add-LabMachineDefinition:Network' = 'ADLab'
                    'Add-LabMachineDefinition:MinMemory' = 1GB
                    'Add-LabMachineDefinition:MaxMemory' = 4GB
                    'Add-LabMachineDefinition:Memory' = 2GB
                    'Add-LabMachineDefinition:Gateway' = '10.213.0.1'
                }

                Add-LabMachineDefinition -Name CONTOSO-DC -Roles RootDC -Memory 3GB
                Add-LabMachineDefinition -Name CONTOSO-ADFS
                Add-LabMachineDefinition -Name CONTOSO-SRV -Roles FileServer
                Add-LabMachineDefinition -Name CONTOSO-PC1 -OperatingSystem 'Windows 11 Enterprise' -Memory 3GB
                Add-LabMachineDefinition -Name CONTOSO-PC2 -OperatingSystem 'Windows 11 Enterprise'
                Add-LabMachineDefinition -Name ADATUM-DC -Roles RootDC -DomainName 'adatum.com'
                Add-LabMachineDefinition -Name CONTOSO-DC2 -Roles DC

                Export-LabDefinition -Force -ExportDefaultUnattendedXml

                Set-Content -Path $using:labContent\ConfiguredVersion.txt -Value 13 -Force
            }
            GetScript = { return $null }
        }

        Script InstallLab
        {
            DependsOn = '[Script]LabDefinition'
            TestScript = {
                $global:labSources = $using:labSources
                Import-Lab -Name ADLab -NoValidation -NoDisplay
                $lab = Get-Lab -Verbose:$false

                $configuredVersion = Get-Content -Path $using:labContent\ConfiguredVersion.txt -ErrorAction SilentlyContinue
                $installedVersion = Get-Content -Path $using:labContent\InstalledVersion.txt -ErrorAction SilentlyContinue

                Import-Module -Name Hyper-V -Verbose:$false
                $vms = Get-VM -Name ADATUM-*,CONTOSO-*

                return @($vms).Count -ge $lab.Machines.Count -and $null -ne $installedVersion -and $configuredVersion -eq $installedVersion
            }
            SetScript = {
                $global:labSources = $using:labSources
                Import-Lab -Name ADLab -NoValidation -NoDisplay
                Install-Lab
                Copy-Item -Path $using:labContent\ConfiguredVersion.txt -Destination $using:labContent\InstalledVersion.txt -Force
            }
            GetScript = { return $null }
        }
    }
}

ADLab -OutputPath $labContent -ConfigurationData @{ AllNodes = @( @{ NodeName = 'localhost'; PsDscAllowPlainTextPassword = $true } ) } | Out-Null

Set-DscLocalConfigurationManager -Path $labContent -Force
Start-DscConfiguration -Path $labContent -Wait -Force -Verbose

from automatedlab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.