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
$Server = "SERVER" # This is your target domain controller | |
Get-ADUser -Filter "enabled -eq `$false" -Server $Server -Properties sAMAccountName, givenName, sn, userAccountControl, mail, employeeID, lastLogonDate | ForEach-Object { | |
$AttrRepMeta = Get-ADReplicationAttributeMetadata -Object $_ -Properties userAccountControl -Server $Server | |
$_ | Add-Member NoteProperty "whenDisabled" $AttrRepMeta.LastOriginatingChangeTime -Force | |
Write-Output $_ | |
} | Where-Object {$_.whenDisabled -ge [DateTime]::Now.AddMonths(-1)} | Select-Object sAMAccountName, givenName, sn, userAccountControl, mail, employeeID, lastLogonDate, whenDisabled | Export-Csv C:\Temp\DisabledUsers.csv -NoTypeInformation -Force |
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
$empid = import-csv c:\Temp\Emp_ID_Import.csv | |
$empid | ForEach-Object { | |
$PSObj = New-Object PSObject -Property @{ | |
SamAccountName_Input = $_.SamAccountName | |
} | |
$Mbx = Get-Mailbox -Identity $_.SamAccountName -ErrorAction SilentlyContinue | |
if ($Mbx) { | |
$PropHash = @{} |
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
$Items = Import-Csv '.\data.csv' | |
$Items | ForEach-Object { | |
#Init our flag for a unique username | |
$Unique = $false | |
#Init our target SamAccountName | |
$Target_SamAccountName = $_.SamAccountName | |
#Init Regex pattern | |
$Pattern = "^$Target_SamAccountName\d*" | |
#Get all existing accounts that have the same SamAccountName regardless of numeric suffix |