Keith
Keith

Reputation: 27

Get-ADUser error, Name is not a parameter for filter

I have a powershell script to get administrators account details from the Active Directory but I am encountering this error. Sorry Im quite new to PowerShell.

Get-ADUser : Invalid type 'System.Object[] Parameter name:name At line:1 char:1

The following is my script:

PROCESS{
$path = Split-Path -parent "$CSVReportPath\*.*" 
$pathexist = Test-Path -Path $path 
If ($pathexist -eq $false) 
{New-Item -type directory -Path $path} 
 
$reportdate = Get-Date -Format ddmmyyyy 

$csvreportfile = $path + "\ALLADUsers_$reportdate.csv" 

$Admin = (Get-ADGroupMember -Identity Administrators | select-object Name

Foreach( $i in $Admin){
 Get-ADUser  -Filter {Name -eq $Admin} -Properties * | select-object DisplayName, samaccountName, Enabled, 
 Created, LastLogonDate | sort-object -Property LastLogonDate |
  }
  Export-Csv -Path $csvreportfile -NoTypeInformation     
 }

Upvotes: 0

Views: 1401

Answers (1)

Doug Maurer
Doug Maurer

Reputation: 8868

You should use $i as that's the variable you declared foreach item in $Admin. Next, use double quotes for the filter and single quotes around the variable.

Get-ADUser -Filter "Name -eq '$i'" -Properties * 

Upvotes: 0

Related Questions