Error while invoking GetType. Could not find member.

Welcome Forums General PowerShell Q&A Error while invoking GetType. Could not find member.

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 9 months ago.

  • Author
    Posts
  • #76600

    Participant
    Topics: 24
    Replies: 25
    Points: 34
    Rank: Member

    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

    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Error while invoking GetType. Could not find member.’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort