-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathauditAllADUserLogonScripts.ps1
13 lines (11 loc) · 1.11 KB
/
auditAllADUserLogonScripts.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
get-adforest | select -ExpandProperty domains -pv domain | foreach{
Get-ADuser -LDAPFilter "(|(scriptpath=*)(homeDirectory=*))" -Properties scriptpath,homeDirectory -Server $domain | `
select @{Name="Domain";Expression={$domain}},SamAccountName,scriptpath,homeDirectory} | `
export-csv "$env:USERPROFILE\Documents\mapping.csv" -NoTypeInformation
get-adforest | select -ExpandProperty domains -pv domain | foreach{
Get-ADuser -LDAPFilter "(scriptpath=*)" -Properties scriptpath,homeDirectory -Server $domain | foreach{
$file = $null;if($_.scriptpath -like "\\*"){$file = get-item ($_.scriptpath -split " ")[0] -ErrorAction SilentlyContinue}
else{$file = get-item "\\$domain\NETLOGON\$(($_.scriptpath -split " ")[0])" -ErrorAction SilentlyContinue}
$_ | select @{Name="Domain";Expression={$domain}},SamAccountName,scriptpath,@{Name="LastModified";Expression={$file.LastWriteTimeUtc}},
@{Name="LastAccessed";Expression={$file.LastAccessTimeUtc}}}} | `
export-csv "$env:USERPROFILE\Documents\scriptDates.csv" -NoTypeInformation