Tuesday, August 4, 2020

Demo:create a custom configuration and upload it to pullserver


-----------------------
PullServerDemoConfig.ps1
---------


param
(
[Parameter(Mandatory)]
[String]$Path
)
Configuration DemoConfig
{
node DemoConfig
{
File TestFile
{
Ensure = 'Present'
Type = 'File'
DestinationPath = "$env:windir\Temp\DSCPullTest_ConfigName.txt"
Contents = "This demo works if you see this"
}
}
}
DemoConfig -OutputPath $Path

New-Configuration.ps1
#New-Configuration.ps1
#-------
$tempConfigPath = Join-Path $env:TEMP "DemoConfig"
if(-not(Test-Path $tempConfigPath -ErrorAction SilentlyContinue)){
New-Item -ItemType Directory -Force $tempConfigPath
}
.\PullServerDemoConfig.ps1 -Path $tempConfigPath
$configurationFolder = $tempConfigPath

"Creating checksum file at location $configurationFolder" | Write-Host
New-DscChecksum -Path $configurationFolder -OutPath $configurationFolder -Verbose -Force

$configUploadFolder = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration\"
"Copying the configuration and checksum iles to $configUploadFolder" | Write-Host
Copy-Item -Path "$configurationFolder\*" -Destination $configUploadFolder

.\New-Configuration.ps1
mof files will be creted in the $env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration\"


No comments:

Post a Comment