IsraelTorres icon

CreateADUser.ps1

IsraelTorres | PRO | 03/15/12 02:47:48 PM UTC | 0 ⭐ | 394 👁️ | Never ⏰ | []
PowerShell |

890 B

|

None

|

0 👍

/

0 👎

# Israel Torres
# 2012-03-14
# Create a simple AD user in AD; establish a password; enable account
Import-Module ActiveDirectory
#
# args: username, password
if($args.Length -eq 2){ 
$username = $args[0]
$password = $args[1]
    if (!(Get-ADUser -filter {SamAccountName -eq $username})) {
        Write-Host "Creating User:$username"
        New-ADUser $username
        Write-Host "Setting User:$username with New Password"
        Set-ADAccountPassword -Identity myTestAdmin -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $password -Force)
        Write-Host "Unlocking User:$username"
        Unlock-ADAccount -Identity $username
        Write-Host "Enabling User:$username"        
        Enable-ADAccount -Identity $username
    }else{
            Write-Host "User: $username already exists; do something else."
    }
}else{
    Write-Host "Usage: .\CreateADUser.ps1 username password"
}
#EOF

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎