Get-ADComputer -filter Strange error & best practice advice

by althought at 2013-04-23 06:37:35

Hi All,

Hoping someone one may be able to assist me with this, as I have lost a few unpleasant hours today & am not getting very far.

I am querying AD for disabled computer objects & want to use the filter parameter to sort out those which have not been disabled in the last x days. (currently using the modified property)

The part causing me problems is this (did have more going on around this, but this appears to be the source of the error;

[code2=powershell]$dt = (get-date) - (new-timespan -days 40)

Get-ADComputer -filter 'modified -lt $dt' -Properties enabled,lastlogontimestamp,OperatingSystem,modified -ea Stop[/code2]
This returns results well enough, but I get left with an error at the end which does not fill me with confidence (see end of post)

My questions are …

1. Why am i getting this error? Assume there is some hidden code going on behind that filter that does not like what I am attempting?
2. Should it work - thinking maybe as it is a lexicographical comparison im not going get what I want anyway ?
3. When spcifying a filter, what are the reasons for choosing a script block Vs ‘’ or "" - I realise they require a slightly different syntax, but dont fully understand why all 3 work?!

Many thanks


Colin

PSMessageDetails :
Exception : Microsoft.ActiveDirectory.Management.ADException: The specified method is not supported —> System.ServiceModel.FaultException: Active Directory returned an error processing the operation.
— End of inner exception stack trace —
at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForExtendedError(String extendedErrorMessage, Exception innerException)
at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForErrorCode(String message, String errorCode, String extendedErrorMessage, Exception innerException)
at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForFaultDetail(FaultDetail faultDetail, FaultException faultException)
at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowException(AdwsFault adwsFault, FaultException faultException)
at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle handle, ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.ADObjectSearcher.PagedSearch(Object& pageCookie, Boolean& hasSizeLimitExceeded, Int32 pageSize, Int32 sizeLimit)
at Microsoft.ActiveDirectory.Management.ADObjectSearchResultEnumerator.System.Collections.IEnumerator.MoveNext()
at Microsoft.ActiveDirectory.Management.Commands.ADFactory1.&lt;GetExtendedObjectFromFilter&gt;d__0.MoveNext()<br> at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase3.OutputSearchResults(IADOPathNode filter)
at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase3.BeginProcessingOverride()<br> at Microsoft.ActiveDirectory.Management.Commands.GetADComputer.BeginProcessingOverride()<br> at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.BeginProcessing()<br>TargetObject : <br>CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException<br>FullyQualifiedErrorId : The specified method is not supported,Microsoft.ActiveDirectory.Management.Commands.GetADComputer<br>ErrorDetails : <br>InvocationInfo : System.Management.Automation.InvocationInfo<br>ScriptStackTrace : at &lt;ScriptBlock&gt;, &lt;No file&gt;: line 7<br>PipelineIterationInfo : {}</blockquote>by ArtB0514 at 2013-04-23 06:57:56<blockquote>[quote]ScriptStackTrace : at &lt;ScriptBlock&gt;, &lt;No file&gt;: line 7[/quote]<br><br>What's line 7? There are only 3 lines in what you showed us.</blockquote>by althought at 2013-04-23 08:40:17<blockquote>Apologies, that error was from before I had simplified it.... this is what is returned from running just those 2 lines; (although I still get results - it does appear to work)<br><br>PSMessageDetails : <br>Exception : Microsoft.ActiveDirectory.Management.ADException: The specified method is not supported ---&gt; System.ServiceModel.FaultException: Active Directory returned an error processing the operation.<br> --- End of inner exception stack trace ---<br> at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForExtendedError(String extendedErrorMessage, Exception innerException)<br> at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForErrorCode(String message, String errorCode, String extendedErrorMessage, Exception innerException)<br> at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForFaultDetail(FaultDetail faultDetail, FaultException faultException)<br> at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowException(AdwsFault adwsFault, FaultException faultException)<br> at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)<br> at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle handle, ADSearchRequest request)<br> at Microsoft.ActiveDirectory.Management.ADObjectSearcher.PagedSearch(Object&amp; pageCookie, Boolean&amp; hasSizeLimitExceeded, Int32 pageSize, Int32 sizeLimit)<br> at Microsoft.ActiveDirectory.Management.ADObjectSearchResultEnumerator.System.Collections.IEnumerator.MoveNext()<br> at Microsoft.ActiveDirectory.Management.Commands.ADFactory1.<GetExtendedObjectFromFilter>d__0.MoveNext()
at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase3.OutputSearchResults(IADOPathNode filter)<br> at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase3.BeginProcessingOverride()
at Microsoft.ActiveDirectory.Management.Commands.GetADComputer.BeginProcessingOverride()
at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.BeginProcessing()
TargetObject :
CategoryInfo : NotSpecified: (:slight_smile: [Get-ADComputer], ADException
FullyQualifiedErrorId : The specified method is not supported,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 3
PipelineIterationInfo : {}
by ArtB0514 at 2013-04-23 10:45:16
Well, I got the same error message as you when I set -ResultSetSize over 256 (the default value is $null – return all data). The solution seems to be upping the ResultPageSize value (default: 256). Coincidence??? Anyway, with further experimenting, it seems that you need to set ResultPageSize greater then the number of items returned. In my case, there are 923 computers that match your filter and setting to 1000 worked.

No clue why this is happening, but at least there’s a work-around.
by althought at 2013-04-24 01:26:35
Good call :-). I was too busy playing ‘change the punctuation’ !

Thank you , most appreciated - can move on with the week now !