-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d22061
commit 0e8f321
Showing
2 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Declare a generic list to store results | ||
[System.Collections.Generic.List[PSObject]] $sidObjectsArray = @() | ||
|
||
# Get all objects with non-empty SIDHistory attribute and include properties sIDHistory,msDS-ReplattributeMetaData,samaccountname | ||
Get-ADobject -LDAPFilter "(sidHistory=*)" -Properties sIDHistory, distinguishedName, samaccountname, 'msDS-ReplattributeMetaData' | ForEach-Object { | ||
# Get the last change date of the SIDHistory attribute | ||
$replattributeMetaData = $_.'msDS-ReplattributeMetaData' | ||
$replattributeMetaData = '<root>' + $replattributeMetaData + '</root>' | ||
$replattributeMetaData = $replattributeMetaData.Replace([char]0, ' ') | ||
$replattributeMetaData = [XML]$replattributeMetaData | ||
$replattributeMetaData = $replattributeMetaData.root.DS_REPL_ATTR_META_DATA | ||
$replattributeMetaData = $replattributeMetaData | Where-Object { $_.pszattributeName -eq 'sIDHistory' } | Select-Object -ExpandProperty ftimeLastOriginatingChange | ||
$lastChangeDate = $replattributeMetaData | Get-Date -Format 'MM/dd/yyyy' | ||
|
||
# create an ordered PSCustomObject to hold the properties of the object | ||
$object = [PSCustomObject][ordered]@{ | ||
SamAccountName = $_.samAccountName | ||
SIDHistory = $_.sIDHistory | ||
LastChangeDate = $lastChangeDate | ||
DistinguishedName = $_.distinguishedName | ||
} | ||
|
||
$sidObjectsArray.Add($object) | ||
} | ||
|
||
# display the list content | ||
$sidObjectsArray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters