Link to home
Start Free TrialLog in
Avatar of Chris Miller
Chris MillerFlag for United States of America

asked on

MODIFY - Powershell script to create a user account to 2 diff domains

I am needing to modify the following script to prompt for cred under both Local-A and Local-B, i have many diff IT Tech Support that will be using this script.

Avatar of Chris Miller
Chris Miller
Flag of United States of America image

ASKER

# Import the Active Directory module
Import-Module ActiveDirectory

# Prompt the user for the required information
$FirstName = Read-Host "Enter First Name"
$LastName = Read-Host "Enter Last Name"
$Username = Read-Host "Enter Username (i.e - FirstinitialLastName)"
$Password = Read-Host "Enter a Password" -AsSecureString
$Description = Read-Host "Enter Description (i.e Entity-City-Dept)"

# Set the common parameters
$CommonParams = @{
    Name = "$FirstName $LastName"
    GivenName = $FirstName
    Surname = $LastName
    SamAccountName = $Username
    Displayname = "$FirstName $LastName"
    Description = $Description
    AccountPassword = $Password
}

# Create the user account in Local-A
$LocalAParams = @{
    UserPrincipalName = "$Username@entity.local-A"
    Path = "OU=Company-Name,DC=entity,DC=local-A"
    Server = "Server-A.Local-A.com"
    Credential = "Local-A\adminaccount"
    Enabled = $true
    ChangePasswordAtLogon = $false
    EmailAddress = "$Username@entity.local-A"
    ErrorAction = 'Stop'
}
New-ADUser @CommonParams @LocalAParams

# Create the user account in Local-B
$LocalBParams = @{
    UserPrincipalName = "$Username@entity.local-B"
    Path = "OU=Company-Name,DC=entity,DC=local-B"
    Server = "Server-B.Local-B.com"
    Credential = "Local-B\adminaccount"
    Enabled = $true
    ChangePasswordAtLogon = $false
    EmailAddress = "$Username@entity.local-B"
    ErrorAction = 'Stop'
}
New-ADUser @CommonParams @LocalBParams

Write-Host -BackgroundColor DarkGreen "Active Directory user account setup complete!"
ASKER CERTIFIED SOLUTION
Avatar of Chris Miller
Chris Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dfke
dfke

Hi,

Great that you got it to work!


Cheers