2017-01-19 27 views
0

我想創建一個powershell審計新創建的帳戶&組和誰創建它們。這些對象由帳戶操作員創建,但它們不是域管理員。Powershell腳本來審計新的AD帳戶和組

我覺得是這樣的:

$Last = (Get-Date).AddDays(-1); 
Get-Acl | Get-ADUser -Filter {WhenCreated -ge $Last} | FL DistinguishedName, Path,owner 

但這並沒有工作。

+1

什麼不行呢?爲什麼不使用本機EventLog事件? [在Active Directory上創建新用戶帳戶時的事件ID](https://social.technet.microsoft.com/wiki/contents/articles/17055.event-ids-when-a-new-user-account-is -created-on-active-directory.aspx) – Seth

+0

我們有很多域控制器,事件日誌在一天內被覆蓋,所以這不是一個選項。 – Jaap2016

+0

如果您從左側刪除了'Get-ACL |',則您的代碼將起作用。 :) – Clayton

回答

0

這一個班輪將讓你知道某個日期後的變化。有一個更改屬性與您可以過濾對象。

Get-ADObject -Filter 'whenchanged -gt $dte' | Group-Object objectclass 

那麼你可以使用:

get-adgroup -filter * | sort name | select Name 

Get-adgroupmember "Name" 

Get-ADGroup -filter "GroupCategory -eq 'Security'" –properties Member | 
Select Name,@{Name="Members"; 
Expression={($_.member | Measure-Object).count}}, 
GroupCategory,GroupScope,Distinguishedname | 
Out-GridView -Title "Select one or more groups to export" -OutputMode Multiple | 
foreach { 
    Write-Host "Exporting $($_.name)" -ForegroundColor cyan 
    #replace spaces in name with a dash 
    $name = $_.name -replace " ","-" 
    $file = Join-Path -path "C:\work" -ChildPath "$name.csv" 
    Get-ADGroupMember -identity $_.distinguishedname -Recursive | 
    Get-ADUser -Properties Title,Department | 
    Select Name,Title,Department,SamAccountName,DistinguishedName | 
    Export-CSV -Path $file -NoTypeInformation 
Get-Item -Path $file 
} 
+0

缺少'$ dte'的定義。它可能與OP中的'Last'相同,但它可以改進包含它的答案。 – Seth

相關問題