Thanks both of you.
I have this:
$EmailAccess = (Get-ADGroup 'Email Access').DistinguishedName
$NoEmailAccess = (Get-ADGroup 'No Email Access').DistinguishedName
Get-ADUser -Filter { (memberof –ne $EmailAccess) –and (memberof –ne
$NoEmailAccess) }" | Export-CSV E:\tmp\NotEmailAccessMembers.csv
Currently the No Email Access group is empty.
I have a distribution Group for exchange called No Internet Email but I can not
get it so come in.
Is that because it is a distribution group and not a security group. Also it
in up one container called NoInternet and not Users?
I can have someone put all the No Internet Email members into the No Email
Access group in Users if I have to.
Just didn’t want to cause the work.
Thanks again.
From: [email protected] [mailto:[email protected]] On
Behalf Of Nathan Shelby
Sent: Thursday, April 7, 2016 3:11 PM
To: [email protected]
Cc: [email protected]
Subject: Re: [NTSysADM] AD Group query
You can simplify it quite a bit
$EmailAccessDn = (Get-ADGroup 'EmailAccess').DistinguishedName
Get-ADUser -LDAPFilter "(!(memberof=$EmailAccessDn))" | Export-CSV
C:\tmp\NotEmailAccessMembers.csv
Script does the following
Gets your group distinguished name and set its as a variable
uses an LDAP Filter (search) with Get-ADUser to perform a NOT EQUAL
'!(member....'
Exports results to CSV
If needed you can expand the group search by adding AND statements to the LDAP
filter and properly formatting the x.500 of the group (e.g.
CN=EmailAccess,OU=Heretherebedragons,DC=domain,DC=local).
Nathan Shelby
Director of Systems Engineering – Quote Wizard<https://quotewizard.com/>
[email protected]<mailto:[email protected]> / 206-753-2626
Malo Periculosam Libertatem Quam Quietum Servitium
On Thu, Apr 7, 2016 at 7:48 AM, David McSpadden
<[email protected]<mailto:[email protected]>> wrote:
I am wanting all users that are not a part of the group ‘Email Access’
What am I doing wrong?
$Users = ForEach ($U in (Get-ADUser -Filter {Enabled -eq "True"}))
{
$UN = Get-ADUser $U -Properties MemberOf
$Groups = ForEach ($Group in ($UN.MemberOf) | Where ($UN.MemberOf) –ne
‘Email Access’)
{
(Get-ADGroup $Group).Name
}
$Groups = $Groups | Sort
ForEach ($Group in $Groups)
{
New-Object PSObject -Property @{
Name = $UN.Name
Group = $Group
}
}
}
$Users | Export-CSV C:\tmp\UserMemberships.csv
David McSpadden
System Administrator
Indiana Members Credit Union
P: 317.554.8190
[Description: Description: imcu email icon]<http://imcu.com/> [Description:
Description: facebook email icon] <https://www.facebook.com/IndianaMembersCU>
[Description: Description: twitter email icon]
<https://twitter.com/IndMembersCU>
[Description: Description: email logo]
[http://www.amuletsolutions.com/images/mcp.gif]<http://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwjFztf-tePJAhXK5iYKHcPtAxEQjRwIBw&url=http://www.amuletsolutions.com/awards.aspx&bvm=bv.110151844,d.amc&psig=AFQjCNHkrx8CednTEOOq4zUxYyrRUGzUsg&ust=1450459757284499>
This e-mail and any files transmitted with it are property of Indiana Members
Credit Union, are confidential, and are intended solely for the use of the
individual or entity to whom this e-mail is addressed. If you are not one of
the named recipient(s) or otherwise have reason to believe that you have
received this message in error, please notify the sender and delete this
message immediately from your computer. Any other use, retention,
dissemination, forwarding, printing, or copying of this email is strictly
prohibited.
Please consider the environment before printing this email.
This e-mail and any files transmitted with it are property of Indiana Members
Credit Union, are confidential, and are intended solely for the use of the
individual or entity to whom this e-mail is addressed. If you are not one of
the named recipient(s) or otherwise have reason to believe that you have
received this message in error, please notify the sender and delete this
message immediately from your computer. Any other use, retention,
dissemination, forwarding, printing, or copying of this email is strictly
prohibited.
Please consider the environment before printing this email.