PowerShell view changes to ad group membership

Source: Internet
Author: User

The forum saw someone asked how to use PowerShell to view the changes in the Administrators group, Beans wrote a very simple script to implement this function, writing is very simple, is a thought to verify a bit.


First get the current group member information, Powershell 3.0 can be used directly after the ad module a lot of commands, a better command is Get-adreplicationattributemetadata, You can get metadata information about an object. For example, I can get the time state created by each member in Testgroup1.

$dn = (get-adgroup "Testgroup1"). distinguishedname get-adreplicationattributemetadata $dn-server syddc01- Showalllinkedvalues | Where-object {$_.attributename-eq ' member '} | Select Firstoriginatingcreatetime, AttributeValue | Export-csv C:\temp\old.csv


As you can see, there are only 2 members of this group

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/BF/wKioL1WnTtCAMMSOAAFvlz4i8oo850.jpg "title=" old. PNG "style=" Float:none; "alt=" wkiol1wnttcammsoaafvlz4i8oo850.jpg "/>


A new member goes in, executes again, and can see the new member change


Get-adreplicationattributemetadata $dn-server syddc01-showalllinkedvalues | Where-object {$_.attributename-eq ' member '} | Select Firstoriginatingcreatetime, AttributeValue | Export-csv C:\temp\new.csv


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6F/C2/wKiom1WnTPLCt1N4AAFwNuHdnVk735.jpg "style=" float: none; "Title=" new. PNG "alt=" Wkiom1wntplct1n4aafwnuhdnvk735.jpg "/>


Save the two results, then use Compare-object to compare, if not empty, send a message

$a =get-content C:\temp\old.csv $b =get-content C:\temp\new.csv $result =compare-object $a $b if ($result) {Send-mailmessa Ge-from "[email protected]"-to "[email protected]"-subject "Test Email"-body $result-smtpserver ultimo-port 25}


The test message appears as follows, and the successful

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/C2/wKiom1WnTgLjDiS2AACSosrkHf8753.jpg "title=" Capture.png "alt=" Wkiom1wntgljdis2aacsosrkhf8753.jpg "/>


This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1675273

PowerShell view changes to ad group membership

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.