Get-ADUser and Filter on Multiple Attributes?
hi all,
i have following script , able filter several different attributes shown below. problem is, there's wrong way have set , cannot figure out...i'm hoping can.
i think multiple "or" statements incorrect, i've tried "and" statements well. thank can offer!
$aduser = get-aduser -filter { (employeetype -notlike "contracto*") -or (title -notlike "pharm*" ) -or (samaccountname -notlike "*train*") -or (samaccountname -notlike "*micro*") -or (samaccountname -notlike "pt*") } -properties * -searchbase "ou=bogusou,dc=bogus,dc=bogus,dc=bogusnet"
$mycol = @()
foreach ($user in $aduser)
{
$myusers = new-object system.object
$myusers | add-member -membertype noteproperty -name samaccountname -value $user.samaccountname
$myusers | add-member -membertype noteproperty -name displayname -value $user.displayname
$myusers | add-member -membertype noteproperty -name department -value $user.department
$myusers | add-member -membertype noteproperty -name city -value $user.l
$myusers | add-member -membertype noteproperty -name telephonenumber -value $user.telephonenumber
$myusers | add-member -membertype noteproperty -name managerempid -value $user.info
$myusers | add-member -membertype noteproperty -name unt -value $user.physicaldeliveryofficename
$myusers | add-member -membertype noteproperty -name divandorg -value (($user.division) + "." + ($user.businesscategory))
$myusers | add-member -membertype noteproperty -name emailaddress -value $user.mail
$mycol += $myusers
$mycol | export-csv c:\output.csv -notypeinformation
}
thank time,
mr mister
you should describe obtaining opposed expecting. otherwise left out guess want.
so here's guess:
- the export-csv cmdlet needs go outside foreeach block. otherwise you'll re-writing file after each iteration. waste of computer cycles , hard drive moving parts. just export once, when array complete.
- are sure -filter parameter of get-aduser accepts powershell expressions? for example, wmi objects accepting filters require filter in wql language. maybe need use ldap filtering syntax here in form of string.
jose r. mcp
code samples
Windows Server > Windows PowerShell
Comments
Post a Comment