105 lines
3.8 KiB
PowerShell
105 lines
3.8 KiB
PowerShell
Write-Host "Running System File Checker (sfc /scannow)"
|
|
$DefaultProcessParam = @{
|
|
'Wait' = $true
|
|
'ErrorAction' = 'Stop'
|
|
}
|
|
$ProcessParam = @{
|
|
'FilePath' = 'sfc'
|
|
'ArgumentList' = '/scannow'
|
|
}
|
|
Start-Process @ProcessParam @DefaultProcessParam
|
|
Write-Host 'Stopping ConfigManager service if it exists'
|
|
Stop-Service -Force 'ccmexec' -ErrorAction 'SilentlyContinue'
|
|
Write-Host 'Stopping Windows Management Instrumentation service'
|
|
Stop-Service -Force 'winmgmt'
|
|
Write-Host 'Temporarily disabling Windows Management Instrumentation service'
|
|
Set-Service -Name 'winmgmt' -StartupType 'Disabled'
|
|
Write-Host 'Determining system architecture'
|
|
if ([System.Environment]::Is64BitOperatingSystem) {
|
|
$WbemBinaries = @(
|
|
"$($env:SystemRoot)\System32\wbem\unsecapp.exe"
|
|
"$($env:SystemRoot)\System32\wbem\WMIADAP.exe"
|
|
"$($env:SystemRoot)\System32\wbem\WMIApSrv.exe"
|
|
"$($env:SystemRoot)\System32\wbem\WmiPrvSE.exe"
|
|
"$($env:SystemRoot)\System32\wbem\scrcons.exe"
|
|
"$($env:SystemRoot)\SysWOW64\wbem\WMIADAP.exe"
|
|
"$($env:SystemRoot)\SysWOW64\wbem\WmiPrvSE.exe"
|
|
)
|
|
$WbemPaths = @(
|
|
"$($env:SystemRoot)\System32\wbem"
|
|
"$($env:SystemRoot)\SysWOW64\wbem"
|
|
)
|
|
}
|
|
else {
|
|
$WbemBinaries = @(
|
|
"$($env:SystemRoot)\System32\wbem\unsecapp.exe"
|
|
"$($env:SystemRoot)\System32\wbem\WMIADAP.exe"
|
|
"$($env:SystemRoot)\System32\wbem\WMIApSrv.exe"
|
|
"$($env:SystemRoot)\System32\wbem\WmiPrvSE.exe"
|
|
"$($env:SystemRoot)\System32\wbem\scrcons.exe"
|
|
)
|
|
$WbemPaths = @(
|
|
"$($env:SystemRoot)\System32\wbem"
|
|
)
|
|
}
|
|
Write-Host "Registering WBEM DLLs"
|
|
foreach ($WbemPath in $WbemPaths){
|
|
$WmiObjects = Get-ChildItem -Path "$WbemPath\*" -Include '*.dll'
|
|
foreach ($WmiObject in $WmiObjects) {
|
|
Write-Host " Registering WBEM DLL $($WmiObject.FullName)"
|
|
$ProcessParam = @{
|
|
'FilePath' = 'regsvr32'
|
|
'ArgumentList' = "/s `"$($WmiObject.FullName)`""
|
|
}
|
|
Start-Process @ProcessParam @DefaultProcessParam
|
|
}
|
|
}
|
|
Write-Host "Registering WBEM EXEs"
|
|
foreach ($WbemBinary in $WbemBinaries) {
|
|
if (Test-Path -Path "$WbemPath\$WbemBinary") {
|
|
$CurrentBin = Get-Item -Path "$WbemPath\$WbemBinary"
|
|
Write-Host " Registering $WbemBinary"
|
|
$ProcessParam = @{
|
|
'FilePath' = $CurrentBin.FullName
|
|
'ArgumentList' = '/RegServer'
|
|
}
|
|
Start-Process @ProcessParam @DefaultProcessParam
|
|
}
|
|
else {
|
|
Write-Warning "File $WbemBinary not found in $WbemPath!"
|
|
}
|
|
}
|
|
Write-Host "Registering WMI Managed Objects"
|
|
$FileExtensions = @(
|
|
'*.mof'
|
|
'*.mfl'
|
|
)
|
|
foreach ($WbemPath in $WbemPaths){
|
|
$WbemDlls = Get-ChildItem -Path "$WbemPath\*" -Include $FileExtensions
|
|
foreach ($WbemDll in $WbemDlls) {
|
|
Write-Host " Registering WBEM DLL $($WbemDll.FullName)"
|
|
$ProcessParam = @{
|
|
'FilePath' = "$WbemPath\mofcomp.exe"
|
|
'ArgumentList' = $WbemDll.FullName
|
|
}
|
|
Start-Process @ProcessParam @DefaultProcessParam
|
|
}
|
|
}
|
|
Write-Host "Resetting Repository"
|
|
$ProcessParam = @{
|
|
'FilePath' = "$($env:SystemRoot)\System32\wbem\winmgmt.exe"
|
|
'ArgumentList' = '/resetrepository'
|
|
}
|
|
Start-Process @ProcessParam @DefaultProcessParam
|
|
Write-Host "Salvaging Repository"
|
|
$ProcessParam = @{
|
|
'FilePath' = "$($env:SystemRoot)\System32\wbem\winmgmt.exe"
|
|
'ArgumentList' = '/salvagerepository'
|
|
}
|
|
Start-Process @ProcessParam @DefaultProcessParam
|
|
Write-Host 'Setting Windows Management Instrumentation service back to Automatic'
|
|
Set-Service -Name 'winmgmt' -StartupType 'Automatic'
|
|
Write-Host 'Starting Windows Management Instrumentation service'
|
|
Start-Service -Force winmgmt
|
|
Write-Host 'Starting ConfigManager service if it exists'
|
|
Start-Service -Force ccmexec -ErrorAction SilentlyContinue |