Error while invoking GetType. Could not find member.

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

Viewing 1 reply thread
  • Author
    Posts
    • #76600
      Participant
      Topics: 25
      Replies: 26
      Points: 49
      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: 18
      Replies: 4872
      Points: 1,903
      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.

Viewing 1 reply thread
  • The topic ‘Error while invoking GetType. Could not find member.’ is closed to new replies.