Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Server = "contoso.co.uk"
- $SearchBase = "OU=People,DC=AD,DC=Contoso,DC=co,DC=uk"
- $AdminOU = "OU=Admin Accounts,OU=IT,OU=contoso,OU=People,DC=AD,DC=contoso,DC=co,DC=uk"
- $Office365 = "OU=Office 365,OU=contoso,OU=People,DC=AD,DC=contoso,DC=co,DC=uk"
- $InactiveDays = 90
- $EmailServer = "exchange"
- $Recipients = "notifications@contoso"
- $WhatIfPreference = $false
- $InactiveUsers = Search-ADAccount -AccountInactive -UsersOnly -TimeSpan (New-TimeSpan -Days $InactiveDays) -Server $Server -SearchBase $SearchBase | Get-ADUser -Properties Created | Where-Object {$_.DistinguishedName -notlike "*,$AdminOU,$Office365" -and $_.Enabled -and $_.Created -lt (Get-Date).AddDays(-30)}
- If ($InactiveUsers) {
- $InactiveUsers | Set-ADUser -Description "Inactive disabled: $(Get-Date -Format D )" -Enabled $false
- $HTML = $InactiveUsers | Sort-Object | ConvertTo-Html -As Table -Fragment -Property Name, @{Label = "Location"; Expression = {$_.DistinguishedName.Split(',')[1].Substring(3)}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement