Skip to content

Instantly share code, notes, and snippets.

@jeremytbrun
jeremytbrun / Get-ADUserWhenDisabled.ps1
Last active March 11, 2019 14:35
Get-ADUserWhenDisabled
$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
@jeremytbrun
jeremytbrun / Get-MailboxShowNulls.ps1
Created February 27, 2019 19:13
Get-MailboxShowNulls
$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 = @{}
@jeremytbrun
jeremytbrun / Get-SharePointListItems.ps1
Last active February 27, 2019 14:15
Get-SharePointListItems
$SiteUrl = "https//mysite.com/sites/my/site"
$ListName = "List Name"
$Cred = Get-Credential
Connect-PnPOnline –Url $SiteUrl –Credentials $Cred
$Fields = Get-PnPField -List $ListName
$ListItems = Get-PnpListItem -List $ListName -Fields $Fields.InternalName | ForEach-Object {
$ListItem = $_
@jeremytbrun
jeremytbrun / Get-UniqueSamAccountNames.ps1
Created February 26, 2019 16:24
Get-UniqueSamAccountNames
$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