PowerShell AD

Soldato
Joined
28 Sep 2008
Posts
14,190
Location
Britain
Does anyone know of a way to set each AD user account to "never expire" in AD? I can't seem to do it for all users, but can for individual users.
 
Not a powershell pro by any means but something like this should work, obviously changing the OU/DC.

Code:
Import-Module ActiveDirectory  
 $users = $i = $null  
 $users = Get-ADUser - Filter * -SearchBase "ou=ou,dc=dc" 
 ForEach($user in $users)  
  {  
    "modifying $($user.name)"  
    Clear-ADAccountExpiration -Identity $user
    $i++  
 }  
"modified $i users"
 
Can be done much simpler:

get-aduser -filter * -ResultSetSize $null| Clear-ADAccountExpiration -whatif

will show you what it will do, take whatif off to actually do the action

get-aduser -filter * -ResultSetSize $null| Clear-ADAccountExpiration
 
Last edited:
Back
Top Bottom