Error while invoking GetType. Could not find member.

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 6 hours, 11 minutes ago.

  • Author
  • #76600


    Hi, I've been trying to get this script to pickup a Domain user (Dom1\V35678) but it never does. I get the Error while invoking GetType. Could not find member message. It picks up every other local admin. Any ideas? Thanks for any help in advance.

    $computerName = '6WGPQG2'
    $localgroupName = "Administrators"
    	if ($computerName -eq "") { $computerName = "$env:computername" }
    	if ([ADSI]::Exists("WinNT://$computerName/$localGroupName,group"))	{
    		$group = [ADSI]("WinNT://$computerName/$localGroupName,group")
    		$members = @()
    		$Group.Members() |
    		% {
    			$AdsPath = $_.GetType().InvokeMember("Adspath", 'GetProperty', $null, $_, $null)
    			# Domain members will have an ADSPath like WinNT://DomainName/UserName.
    			# Local accounts will have a value like WinNT://DomainName/ComputerName/UserName.
    			$a = $AdsPath.split('/', [StringSplitOptions]::RemoveEmptyEntries)
    			$name = $a[-1]
    			$domain = $a[-2]
    			$class = $_.GetType().InvokeMember("Class", 'GetProperty', $null, $_, $null)
    			$member = New-Object PSObject
    			$member | Add-Member -MemberType NoteProperty -Name "Name" -Value $name
    			$member | Add-Member -MemberType NoteProperty -Name "Domain" -Value $domain
    			$member | Add-Member -MemberType NoteProperty -Name "Class" -Value $class
    			$members += $member
    write-output $members
  • #77463

    Don Jones

    Finally got a chance to play with this, and my best guess is that it's falling apart in the COM Interop layer. You might be better off switching to a pure .NET Framework approach, or using the AD module from the RSAT. ADSI is pretty creaky these days.

You must be logged in to reply to this topic.