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