Skip to content

Instantly share code, notes, and snippets.

@SteveL-MSFT
Last active March 27, 2021 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveL-MSFT/f4a794f5002c2e06d2e99dff447896ef to your computer and use it in GitHub Desktop.
Save SteveL-MSFT/f4a794f5002c2e06d2e99dff447896ef to your computer and use it in GitHub Desktop.
Example script showing auto-correction with DSC and PS7
Start-Job {
# path would need to be updated to where you have the FileContentResource.psm1 example saved
if ($env:PSModulePath -notlike "*demo*") {
$env:PSModulePath += [System.IO.Path]::PathSeparator + '/Users/steve/test/demo'
}
# temporarily ensure latest version required for this demo is loaded
Import-Module /Users/steve/test/demo/PSDesiredStateConfiguration -Force
$dscParams = @{
ModuleName = 'FileContentResource'
Name = 'FileContentResource'
Property = @{
filePath = '/Users/steve/test/demo/test.txt'
content = 'DSC Rocks!'
}
}
while ($true) {
if (!(Invoke-DscResource @dscParams -Method Test).InDesiredState) {
Invoke-DscResource @dscParams -Method Set
}
Start-Sleep -Seconds 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment