Get-PC/Private/ResetRepository.ps1

28 lines
906 B
PowerShell
Raw Normal View History

2024-06-11 18:27:55 +00:00

Function Get-ResetRepository($ComputerName){
Write-Host "Verifying if WMI Repository is corrupt..." -ForegroundColor Yellow
Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock{
$isCorrupt = & Winmgmt /verifyrepository
if($isCorrupt -eq "WMI repository is consistent"){
Write-Host "WMI repository is consistent, no need to reset repository on $Using:ComputerName" -ForegroundColor Green
break
}else{
Write-Host "WMI repository is corrupt, resetting repository on $Using:ComputerName" -ForegroundColor Red
Write-Host "Will attempt to Salvage Repository..."
& Winmgmt /salvagerepository
Write-Host "Salvage Repository has finished." -ForegroundColor Green
}
}
}