PowerShell: DSC Sometimes Killing The Provider Isn't Enough...
A timely post considering the previous one. I've had a lot of problems with configurations just seemingly not taking affect. The only way I've seen to clear this up is by deleting the following files on the target machine:
"C:\Windows\System32\Configuration\Current.mof" "C:\Windows\System32\Configuration\Current.mof.checksum" "C:\Windows\System32\Configuration\DSCEngineCache.mof" "C:\Windows\System32\Configuration\backup.mof"
In my case I was syncing files and for the life of me could not get it to see the newest addition to the directory, I could delete older files/folders and it would replace them, but it patently refused to ever copy out the new one. Deleted these files, let DSC run, I could delete the new file/folder to my hearts content and it would always put it back down next time DSC passed.
To batch fix your servers (this assumes you have them all in an AD group, you could just create an array and pass it):
if($creds -eq $null){ $creds = Get-Credential } foreach($member in (Get-ADGroupMember <groupname>)) { $member.Name Invoke-Command -ComputerName $member.Name -Credential $creds -Scriptblock{ $strPath = "C:\Windows\System32\Configuration\" $arFiles = @("Current.mof","Current.mof.checksum","DSCEngineCache.mof","backup.mof") foreach($item in $arFiles) { Write-Host "Removing: $strPath$item" Remove-Item -Path "$strPath$item" -Force } } } Write-Host "This is a test, and can be removed later." return $false
Be warned that this should ONLY be done if you are having the problem accross the board, otherwise just invoke-command on the individual servers or, if only a portion are having problems just feed in an array. In my case EVERY server was failing on this File operation so killing it accross the board made sense. But it is still not something I would take lightly (batch deleting files never is).