@@ -236,8 +236,8 @@ function Get-ADDSPrivilegedAccountAudit {
236
236
@ {N = ' PriviledgedGroup' ; E = { $group } }, `
237
237
@ {N = ' Enabled' ; E = { (Get-ADUser - Identity $_.samaccountname ).Enabled } }, `
238
238
@ {N = ' PasswordNeverExpires' ; E = { (Get-ADUser - Identity $_.samaccountname - Properties PasswordNeverExpires).PasswordNeverExpires } }, `
239
- @ {N = " LastSign-in " ; E = { [DateTime ]::FromFileTime((Get-ADUser - Identity $_.samaccountname - Properties lastLogonTimestamp).lastLogonTimestamp) } }, `
240
- @ {N = ' LastSeen? ' ; E = {
239
+ @ {N = ' LastLogin ' ; E = { [DateTime ]::FromFileTime((Get-ADUser - Identity $_.samaccountname - Properties lastLogonTimestamp).lastLogonTimestamp) } }, `
240
+ @ {N = ' LastSeen' ; E = {
241
241
switch ([DateTime ]::FromFileTime((Get-ADUser - Identity $_.samaccountname - Properties lastLogonTimestamp).lastLogonTimestamp)) {
242
242
# Over 90 Days
243
243
{ ($_ -lt $time90 ) } { ' 3+ months' ; break }
@@ -262,30 +262,31 @@ function Get-ADDSPrivilegedAccountAudit {
262
262
} # end else
263
263
}
264
264
}, # End Named Expression SuspectedSvcAccount
265
- Department, " AccessRequired? " , " NeedMailbox? " - OutVariable members | Out-Null
265
+ Department, AccessRequired, NeedMailbox - OutVariable members | Out-Null
266
266
$ADUsers += $members
267
267
}
268
268
$Export = @ ()
269
269
# Create $Export Object
270
270
foreach ($User in $ADUsers ) {
271
- New-Object - TypeName PSCustomObject - Property @ {
271
+ $hash = [ordered ]@ {
272
+ PriviledgedGroup = $User.PriviledgedGroup
272
273
SamAccountName = $User.SamAccountName
273
274
Name = $User.Name
274
- PriviledgedGroup = $User.PriviledgedGroup
275
- Enabled = $User.Enabled
276
- PasswordNeverExpires = $User.PasswordNeverExpires
277
- SuspectedSvcAccount = $User.SuspectedSvcAccount
278
- " LastSign-in" = $User ." LastSign-in"
279
- " LastSeen?" = $User ." LastSeen?"
275
+ ObjectClass = $User.ObjectClass
276
+ LastLogin = $User.LastLogin
277
+ LastSeen = $User.LastSeen
278
+ GroupMemberships = $User.GroupMemberships
280
279
Title = $User.Title
281
280
Manager = $User.Manager
282
281
Department = $User.Department
283
282
OrgUnit = $User.OrgUnit
284
- " AccessRequired?" = $User ." AccessRequired?"
285
- " NeedMailbox?" = $User ." NeedMailbox?"
286
- ObjectClass = $User.ObjectClass
287
- GroupMemberships = $User.GroupMemberships
288
- } - OutVariable PSObject | Out-Null
283
+ Enabled = $User.Enabled
284
+ PasswordNeverExpires = $User.PasswordNeverExpires
285
+ SuspectedSvcAccount = $User.SuspectedSvcAccount
286
+ AccessRequired = $false
287
+ NeedMailbox = $true
288
+ }
289
+ New-Object - TypeName PSCustomObject - Property $hash - OutVariable PSObject | Out-Null
289
290
$Export += $PSObject
290
291
}
291
292
# Create filenames
@@ -308,10 +309,11 @@ function Get-ADDSPrivilegedAccountAudit {
308
309
# Export Delegated access, allowed protocols and Destination Serivces.
309
310
$Export3 = Get-ADObject - Filter { (msDS- AllowedToDelegateTo -like ' *' ) -or (UserAccountControl -band 0x0080000 ) -or (UserAccountControl -band 0x1000000 ) } `
310
311
- prop samAccountName, msDS- AllowedToDelegateTo, servicePrincipalName, userAccountControl | `
311
- Select-Object DistinguishedName, ObjectClass, samAccountName, servicePrincipalName, `
312
- @ {name = ' DelegationStatus' ; expression = { if ($_.UserAccountControl -band 0x80000 ) { ' AllServices' }else { ' SpecificServices' } } }, `
313
- @ {name = ' AllowedProtocols' ; expression = { if ($_.UserAccountControl -band 0x1000000 ) { ' Any' }else { ' Kerberos' } } }, `
314
- @ {name = ' DestinationServices' ; expression = { $_ .' msDS-AllowedToDelegateTo' } }
312
+ Select-Object DistinguishedName, ObjectClass, samAccountName, `
313
+ @ {N = ' servicePrincipalName' ; E = { $_.servicePrincipalName -join " | " } }, `
314
+ @ {N = ' DelegationStatus' ; E = { if ($_.UserAccountControl -band 0x80000 ) { ' AllServices' }else { ' SpecificServices' } } }, `
315
+ @ {N = ' AllowedProtocols' ; E = { if ($_.UserAccountControl -band 0x1000000 ) { ' Any' }else { ' Kerberos' } } }, `
316
+ @ {N = ' DestinationServices' ; E = { $_ .' msDS-AllowedToDelegateTo' } }
315
317
# Try first export.
316
318
Export-AuditCSVtoZip - Exported $Export - CSVName $csv - ZipName $zip - ErrorVariable ExportAuditCSVZipErr
317
319
# Try second export.
0 commit comments