Mitre
Mitre

Reputation: 273

POWERSHELL ADSI Invoke - poor time performance

Hello i got this problem. Im using Powershell and ADSI to look on Users/Groups that are set on computer. My script working as it should but i got problem with poor time performance. To check some computer it takes few miliseconds but on others it could be 20-40 seconds. Problem is causing this piece of code $data4 = $group.Invoke("Members") . I timed it with measure-command and it is causing that big time sink.

Here is my code snippet.

$group = [ADSI]"WinNT://$computerName/Administrators"
    $members = @()
    $data4 = $group.Invoke("Members") #<--This is cause of poor time performance
    foreach($item in $data4)
    {
        $members += $item.GetType().InvokeMember("Name", 'GetProperty', $null, $item, $null)
    }

Has anybody encountered this or similar problem? Thanks for your help.

Upvotes: 1

Views: 900

Answers (1)

Bill_Stewart
Bill_Stewart

Reputation: 24565

Try including the domain or workgroup name before the computer name. That is, instead of just

WinNT://computername/Administrators

use

WinNT://fabrikam/computername/Administrators

I would also recommend appending the class name after the object name to tell ADSI which object type you want; e.g.:

WinNT://fabrikam/computername/Administrators,Group

Upvotes: 2

Related Questions