Snippet of the script that I am executing :
$reader = $managementgroupobj.GetMonitoringPerformanceDataReader()
while ($reader.Read()) // << Error in this line.
{
$perfData = $reader.GetMonitoringPerformanceData()
$valueReader = $perfData.GetValueReader($starttime,$endtime)
while ($valueReader.Read())
{
$perfValue = $valueReader.GetMonitoringPerformanceDataValue()
}
}
Here, $managementgroupobj
is an instance of class ManagementGroup
.
The difference of $starttime
and $endtime
veries from 15 minutes to 1 hour depending on the last execution of the same script.
The snippet collects the performance the data successfully for long time. but then, out of nowhere it throws following error:
"The requested reader was not valid. The reader either does not exist or has expired"
[ log_level=WARN pid=2716 ] Execute command 'get-scomallperfdata' failed. The requested reader was not valid. The reader either does not exist or has expired.
at GetSCOMPerformanceData, E:\perf\scom_command_loader.ps1: line 628
at run, E:\perf\scom_command_loader.ps1: line 591
at <ScriptBlock>, E:\perf\scom_command_loader.ps1: line 815
at <ScriptBlock>, <No file>: line 1
at <ScriptBlock>, <No file>: line 46
at Microsoft.EnterpriseManagement.Common.Internal.ServiceProxy.HandleFault(String methodName, Message message)
at Microsoft.EnterpriseManagement.Common.Internal.EntityObjectsServiceProxy.GetObjectsFromReader(Guid readerId, Int32 count)
at Microsoft.EnterpriseManagement.Common.DataReader.Read()
at CallSite.Target(Closure , CallSite , Object )
Note:
Thanks.
The reader call will return true
if the reader moved to the next result and false
if not; according to the method's documentation. If you are getting an exception, it couldn't do either of those. I'd assume something broke the connection between you and the SCCM instance.
If it's a timeout issue, I'm not sure it's an SCCM timeout. The error doesn't say anything about a timeout. As far as I know, this is an RPC call under the hood, and RPC doesn't have a timeout:
There are two ways your client can hang: network connectivity can cause server requests to become lost, or the server itself can crash. With default options, RPC will never time out a call, and your client thread will wait forever for a response.
Maybe a firewall is closing your connection after a certain period of time?
If you want to dial-in your performance, consider caching. It looks like you've got a much larger script that the snippet we see. Tossing this out just to make you aware its an option.