Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Exclude security groups from Get-ADUser

$
0
0

I’m new to Powershell and I’m trying to use Powershell to generate a list of inactive user accounts. I have been able to get this to work with some research and borrowing code from others. I now have a need to exclude specific security groups from the results. I attempted to use the -LDAPFilter parameter but this cause a pipeline error. Is it possible to do this in Powershell and what would be the best approach?

Search-ADAccount -UsersOnly -AccountInactive -DateTime "10/05/2011" -ResultPageSize 2000 -ResultSetSize $null -SearchBase "targetOU" -SearchScope Subtree -Server serverFQDN`
|Get-ADUser -Properties * -LDAPFilter "(&(&(objectCategory=User))(!(memberOfDNofsecuritygroup)))"| Select DisplayName,SamAccountName, `
@{n="LastLogonTimeStamp";
e={[DateTime]::FromFileTime($_.lastlogon)}},`
@{name='MemberOf'; expression={ ($_.MemberOf | ForEach { ($_ -split ',')[0] -replace 'CN=',''}) -join ','}}| Export-Csv c:\results.txt


Viewing all articles
Browse latest Browse all 13067

Trending Articles