Get-ADComputer -filter Strange error & best practice advice

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #5838

    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.ADFactory`1.d__0.MoveNext()
    at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.OutputSearchResults(IADOPathNode filter)
    at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.BeginProcessingOverride()
    at Microsoft.ActiveDirectory.Management.Commands.GetADComputer.BeginProcessingOverride()
    at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.BeginProcessing()
    TargetObject :
    CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException
    FullyQualifiedErrorId : The specified method is not supported,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
    ErrorDetails :
    InvocationInfo : System.Management.Automation.InvocationInfo
    ScriptStackTrace : at , : line 7
    PipelineIterationInfo : {}

    by ArtB0514 at 2013-04-23 06:57:56

    [quote]ScriptStackTrace : at , : line 7[/quote]

    What's line 7? There are only 3 lines in what you showed us.

    by althought at 2013-04-23 08:40:17

    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)

    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.ADFactory`1.d__0.MoveNext()
    at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.OutputSearchResults(IADOPathNode filter)
    at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.BeginProcessingOverride()
    at Microsoft.ActiveDirectory.Management.Commands.GetADComputer.BeginProcessingOverride()
    at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.BeginProcessing()
    TargetObject :
    CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException
    FullyQualifiedErrorId : The specified method is not supported,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
    ErrorDetails :
    InvocationInfo : System.Management.Automation.InvocationInfo
    ScriptStackTrace : at , : 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 !

You must be logged in to reply to this topic.