Right now I am trying to understand something and I had this written down from over a year ago but it does not seem right.
I have the following syntax:
SYNTAX
Get-ADUser [-AuthType {Negotiate | Basic}] [-Credential ] [-Properties ] [-ResultPageSize ] [-ResultSetSize ] [-SearchBase ] [-SearchScope {Base | OneLevel
| Subtree}] [-Server ] -Filter
Get-ADUser [-Identity] [-AuthType {Negotiate | Basic}] [-Credential ] [-Partition ] [-Properties ] [-Server ] []
Get-ADUser [-AuthType {Negotiate | Basic}] [-Credential ] [-Properties ] [-ResultPageSize ] [-ResultSetSize ] [-SearchBase ] [-SearchScope {Base | OneLevel
| Subtree}] [-Server ] -LDAPFilter []
If you look at the parameter -filter it does not have brackets around it which means its not optional it must be there correct?
This means -filter must be listed but only for the first ADuser listed.
I read down and see under description that it states to get more help on -filter type get-help about_activeDirectory_Filter so I am now reading about that and its given me some clues to what I want.
They have examples but when I try to some something slight different its not working. Notice how I try to use two conditions the first I have to use in order to get my information out of the CSV where it can be understood and then I say and hey it needs to be enabled. I dont know if its my qoutes that are messing this up or I am breaking some type of rule.
-------------------------------------------MY REWRITTEN CODE-----
$Users=Import-Csv C:\scripts\Yammer.csv
foreach($u in $Users)
{
Get-ADUser -Filter “emailaddress -eq ‘$($u.emailaddress)’” -and ‘Enabled -eq $’ -properties *| Select-Object Name, samaccountname | export-csv -NoTypeInformation c:\scripts\YAM.csv -Append
}
------------------ERROR------------
Get-ADUser : A parameter cannot be found that matches parameter name ‘and’.
At line:4 char:60
- Get-ADUser -Filter “emailaddress -eq ‘$($u.emailaddress)’” -and ‘Enabled -eq $’ …
-
~~~~
- CategoryInfo : InvalidArgument: (
[Get-ADUser], ParameterBindingException
- FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser
next I worked on my quotes trying to mimic the examples and I got it where I was not getting errors:
$Users=Import-Csv C:\scripts\Yammer.csv
foreach($u in $Users)
{
Get-ADUser -Filter ‘emailaddress -eq “$($u.emailaddress)” -and Enabled -eq $true’ -properties *| Select-Object Name, samaccountname | export-csv -NoTypeInformation c:\scripts\YAM.csv -Append
}
However, now my output to CSV is blank…
My thinking is the following:
- get-aduser (but I am not giving it an aduser so we use the filter to say do this by email and here is the email from the csv
- next part is and in addition make sure that enabled is set to true. (this has to be flawed thinking here)
- next list the properties
- last step places this information in CSV
I need to understand why my thinking is flawed. I know there is complex ways to do things but with my existing code I am missing some key process in my thinking.