Skip to content

Instantly share code, notes, and snippets.

View 9to5IT's full-sized avatar

9to5IT 9to5IT

View GitHub Profile
@9to5IT
9to5IT / Manage-ADComputers.ps1
Created July 4, 2016 12:06
PowerShell: Cleanup inactive AD computer objects
Import-Module ActiveDirectory
# Set the number of days since last logon
$DaysInactive = 90
$InactiveDate = (Get-Date).Adddays(-($DaysInactive))
#-------------------------------
# FIND INACTIVE COMPUTERS
#-------------------------------
# Below are three options to find inactive computers. Select the one that is most appropriate for your requirements:
@9to5IT
9to5IT / Manage-ADGroups.ps1
Created July 4, 2016 12:08
PowerShell: Cleanup empty AD Groups
Import-Module ActiveDirectory
#-------------------------------
# FIND EMPTY GROUPS
#-------------------------------
# Get empty AD Groups within a specific OU
$Groups = Get-ADGroup -Filter { Members -notlike "*" } -SearchBase "OU=GROUPS,DC=testlab,DC=com" | Select-Object Name, GroupCategory, DistinguishedName
#-------------------------------
@9to5IT
9to5IT / Manage-ADOUs.ps1
Created July 4, 2016 12:09
PowerShell: Cleanup empty AD OUs
Import-Module ActiveDirectory
#-------------------------------
# FIND EMPTY OUs
#-------------------------------
# Get empty AD Organizational Units
$OUs = Get-ADOrganizationalUnit -Filter * | ForEach-Object { If ( !( Get-ADObject -Filter * -SearchBase $_ -SearchScope OneLevel) ) { $_ } } | Select-Object Name, DistinguishedName
#-------------------------------