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 } } }