One of the easiest way of working with WMI is using Powershell. In this particular case, it is necessary to create an object based on the WMI object to be altered, changing the desired value on this object and then replacing the original object with the modified one.
A WMI service restart is needed. As always, it is a good idea to backup the WMI repository before attempting any changes.
To address all these issues in a consistent manner, a PowerShell script has been created.
When running the script the WMI repository is automatically saved to c:\WMIbackup_<Guid>.rec. A recovery script called c:\WMIbackup_<Guid>.ps1 is created as well.
If necessary, running c:\WMIbackup_<Guid>.ps1 results in restoring the original WMI repository (and values).
Once this is done, the script prompts the user to change the WMI Quota handle count to the desired value. Since the most likely value to use is 8192, hitting enter will do this. To make the value active, the WMI service needs to be restarted and the script gives you this option as well.
The script is fully documented. To display the documentation, run
get-help .\WMIQuotaHandleCountFix.ps1 -full
in an elevated PowerShell console from the directory hosting the script.
The script code is shown below between hosizontal lines and attached to the KB
___________________________________________________________________
<#
.Synopsis
This script allows modifying the WMI Quota handle count
.Description
When running the script the WMI repository is automatically saved to c:\WMIbackup_<Guid>.rec
An recovery script called c:\WMIbackup_<Guid>.ps1 is created as well.
If necessary, running c:\WMIbackup_<Guid>.ps1 results in restoring the original WMI repository (and values).
Once this is done, you can change the WMI Quota handle count to the desired value.
To make the value active, the WMI service needs to be restarted.
The script gives you this option.
#>
Write-Host "`r`nChange the WMI Handles Per Host Value`r`n-------------------------------------`r`nDefault WMI Value: 4096`r`n"
#get WMI service state
$sstate = (get-service winmgmt).Status
if($sstate -ne "Running"){
Write-Host "The WMI Service is in the $($sstate) state. It should be running. Exiting now..." -f yellow;
exit
}
#backup WMI repository
$path= "C:\WMIbackup_$([GUID]::NewGuid())"
$path0 ="$($path).rec"
$path1 = "$($path).ps1"
Write-Host "`r`nBacking up WMI Repository at $path..."
$exp = "winmgmt /backup $path"
Invoke-Expression -Command $exp
Write-Host "Done!`r`n"
$recoveryscript = @"
#Recovery Script for $path0
Write-Host "Restoring WMI..." -f yellow
`$exp = "Winmgmt /restore $path 1 "
Write-Host "Restarting the WMI service and dependencies" -f yellow
restart-service winmgmt -passthru -force
"@
out-file -FilePath $path1 -InputObject $recoveryscript
Write-Host @"
Please note that two files have been created in the root of C:
These files are:
* the backup : $path0
* the recovery script : $path1
To recover this backup, please run $path1
(Both files need to be in the root of c:)
"@ -f Yellow
#get current value
$x = (get-wmiobject -Namespace root -class __providerhostquotaconfiguration)
Write-Host "`r`nCurrent WMI Handles Per Host Value: $($x.HandlesPerHost)`r`n"
#set the new value
$y = Read-Host "Desired value `[default 8192`]"
if($y -eq ""){$y="8192"}
$x.handlesperhost = $y
$x.put()
#Showing that all is OK
$x = (get-wmiobject -Namespace root -class __providerhostquotaconfiguration)
Write-Host "Current WMI Handles Per Host Value: $($x.HandlesPerHost)`r`n"
#restarting the WMI service
$ok = Read-Host "OK to restart the WMI Service? `[default <CR>`]"
if ($ok -ne ""){
Write-Host "`r`nExiting without restarting WMI. Current WMI Handles Per Host Value is $($x.handlesperhost). Exiting...";exit;
}
restart-service winmgmt -PassThru -Force
___________________________________________________________________