Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Scripting the addition of new AD users (will eventually use this for crafting a bulk import with an Import-CSV and foreach loop) but I'm having some difficulty with the AccountExpirationDate property.. We get a kids coming in from other schools just for a few weeks, so I wanted to add an automatic disable for one month after creation.. I found a few sources saying AccountExpirationDate takes multiple different forms of input so I was hoping to use..

 

$ExpirationDate = ((Get-Date).AddMonths(1))
New-ADUser `
-SamAccountName $UserName `
-UserPrincipalName $UserPrincipalName `
-Name $UserName `
-DisplayName $UserName `
-GivenName $Forename `
-SurName $Surname `
-Description "Pupil - Temporary" `
-AccountExpirationDate = $ExpirationDate `
-EmailAddress $UserPrincipalName `
-HomeDrive "H" `
-HomeDirectory $HomeDirectory `
-Path $Path `
-ProfilePath "[b]Local profile path[/b]" `
-AccountPassword (ConvertTo-SecureString "[b]DefaultPassword[/b]" -AsPlainText -force) `
-Enabled $True `
-ChangePasswordAtLogon $True

but this doesn't seem to be working.. Having some difficulty finding a crafted example of this for me to modify, though.. Anybody used it before can set me straight?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...