Skip to content

Instantly share code, notes, and snippets.

@technion
Last active June 29, 2020 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technion/c44c79769d345513ee7215b93dd2e59d to your computer and use it in GitHub Desktop.
Save technion/c44c79769d345513ee7215b93dd2e59d to your computer and use it in GitHub Desktop.
Set-StrictMode -Version 2
Add-Type -AssemblyName 'System.Web'
$adusers = Get-ADGroupMember "Team"
foreach ($user in $adusers) {
$newname = "$($user.Samaccountname).delegate"
$password = [System.Web.Security.Membership]::GeneratePassword(12, 0)
$secPw = ConvertTo-SecureString -String $password -AsPlainText -Force
write-host "Creating delegate user $newname for account with password $password"
New-ADUser -Path "OU=stuff" `
-AccountPassword $secPw -Name "$($user.Name) Full" -Enabled $true `
-UserPrincipalName "$newname@au" -SamAccountName "$newname"
Get-ADUser $user | Set-ADUser -Add @{extensionAttribute13=$newname}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment