Jenkins DSC Compile Mofs

# Configure Environment
$ErrorActionPreference = 'Stop'
Set-Location -Path $env:WORKSPACE


# Initialize variables
[string]$configpath = 'C:\Program Files\WindowsPowerShell\DscService\Configuration'


write-output "Setting PSModulePath..."
$env:PSModulePath = 'C:\Program Files\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules'


Write-Output "Setting secure string..."
$securePassword = ConvertTo-SecureString -String $($env:LocalAdminPassword) -AsPlainText -Force


Write-Output "Writing MOF..."
Try{
& ".\$($env:ConfigName).ps1" -LocalAdminID $($env:LocalAdminID) -LocalAdminPassword $securePassword -Verbose | Out-Null
}Catch{
Throw $_.Exception.Message
}


Write-Output "Creating Checksum..."
New-DscChecksum -Path ".\$($env:ConfigName)\localhost.mof" -OutPath ".\$($env:ConfigName)" -ErrorAction Stop


Write-Output "Renaming MOF file..."
Rename-Item -Path ".\$($env:ConfigName)\localhost.mof" -NewName "$($env:ConfigName).mof" -ErrorAction Stop


Write-Output "Renaming checksum file..."
Rename-Item -Path ".\$($env:ConfigName)\localhost.mof.checksum" -NewName "$($env:ConfigName).mof.checksum" -ErrorAction Stop


Write-Output "Copying MOF to $configpath..."
Copy-Item -Path ".\$($env:ConfigName)\$($env:ConfigName).mof" -Destination $configpath -ErrorAction Stop


Write-Output "Copying checksum to $configpath..."
Copy-Item -Path ".\$($env:ConfigName)\$($env:ConfigName).mof.checksum" -Destination $configpath -ErrorAction Stop

Document Actions