We have following powershell script
$scopes = Get-DhcpServerv4Scope -ComputerName $DHCPservername | select ScopeId, Name
$DHCPservername = "dhcp.company.local"
Foreach ($s in $scopes)
{
write-host "Getting statistics for" $s.ScopeId $s.Name
Get-DhcpServerv4ScopeStatistics -ComputerName $DHCPservername -ScopeID $s.ScopeId
}
This has been simplified to narrow down the issue. Basically we want to get all the scopes on a DHCP server and get the scopeID (which is the network ID like 172.16.0.0.
When we run this script, on some entries whithin the foreach, we get following error:
Get-DhcpServerv4ScopeStatistics : Failed to enumerate reserved IP addresses in scope 172.17.246.32 on DHCP server dhcp.company.local.
At line:7 char:9
- Get-DhcpServerv4ScopeStatistics -ComputerName $DHCPservername ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : PermissionDenied: (172.17.246.32:root/Microsoft/...ScopeStatistics) [Get-DhcpServerv4ScopeStatistics], CimException
- FullyQualifiedErrorId : WIN32 5,Get-DhcpServerv4ScopeStatistics
This is very sporadic. We have around 112 scopes and when we run the script 20 times, sometimes there is no error at all, then there is this error on one scope alone, another run, again maybe only one error but on a different scope and sometimes there are even multiple errors where 3-5 scopes return the message above. Clearly this is no permission issue, because we have permission for all the other scopes and the error switches from run to run. We tested some delays (1s wait in the foreach) which did not help.
We have multiple powershell scripts running on this server as it is our monitoring server. I tested this script on another server, that does not do other powershell scripts, and i coulnt reproduce the issue there. So this seems to be related with something like: running multiple powershell scripts at once or in parralel or something. I couldnt find any limitations on that regard online. So is there something i can test or adjust to increase the amount of powershell processes somehow?