I am new to DSC. Spent the best part of Sunday afternoon looking at the resources and trying to figure out how to solve this. So, I sincerely thank you for that. It was fun looking up on DSC.
I think, this could work:
Configuration TestRun
{
Param
(
$ComputerName = 'Localhost'
)
Node $ComputerName
{
Script RemoveModules {
GetScript = {#needs to return hashtable.}
SetScript = {
$ump = "$HOME" + "\Documents\WindowsPowerShell\Modules\"
Remove-Item -Path $ump -Recurse -Force
}
TestScript = {
$ump = "$HOME" + "\Documents\WindowsPowerShell\Modules\"
$mp = "C:\git\Modules"
if((Compare-Object $(gci $mp) $(gci $ump))){
$false #at least one difference exists, SetScript will be called.
}else{
$true #nothing is different
}
}
}
File LoadModules
{
Ensure = 'Present'
Type = 'Directory'
Force = $true
Recurse = $true
SourcePath = "C:\git\Modules"
DestinationPath = 'C:\users\Jason\Documents\WindowsPowerShell\Modules'
DependsOn = "[Script]RemoveModules"
Checksum = "SHA-256"
MatchSource = $true
}
}
}
References: