Creation of a new starter script

I was looking for some help with a script I have set up for our new starters in active directory. I already have a prompt set up to get the user name of the employee and the employee who I am to copy from.

I have 2 things I am looking to add to this.

  1. I want to be able to move the employee to the same OU as the user I will be copying permissions from.

  2. I want to be able to set the homefolder on the profile tab in AD but with the connect tick selected and using drive Z:. I managed to use the set-aduser to add a homefolder previously but it went in the local path line.

Any help is much appreciated.

Hello $$Hero,

for your first question you can extract the distinguishedName property from the original user and when you use the New-AdUser cmdlet use the -Path parameter.

for your second question you can use the parameter of HomeDirectory parameter.

Here is an example :

$originalUser = get-aduser -Identity ‘DemoUser’
$param = @{
name = ‘NewUser’
Enabled = $true
path = $originalUser.DistinguishedName.Substring($originalUser.DistinguishedName.IndexOf(‘,’)+1)
accountpassword = ‘YourOriginalPassword**’ | ConvertTo-SecureString -AsPlainText -Force
PasswordNeverExpires = $false
HomeDirectory = ‘\MyServer\Share\Users’

new-aduser @param

In this example I am using a HashTable to hold all of the parameters that New-AdUser cmdlet uses, then I am using splatting (new-aduser @param) , this technique transfers the hashtable to the cmdlet as parameters. This makes the code more readable and you can easily change/add/remove parameters.

Hope this helps

Hi @gad-lev-ari

Thanks for the quick reply. In my environment I am required to set up the users manually in Exchange first and then run my script to complete extra fields in AD. Could I still use the distinguished name property to move the new user?

Presumably if I get it as a variable I would use set-aduser -identity $newuser -path $newOU as an example?

Hello SSHero and welcome…

I’d urge you to rethink using existing users as templates for creating new users. It may end up in unintentionally giving the new user more access than they should have.

Here’s a thread you may want to have a look at. The OP is also building a script for AD-account creation.

matt-bloomfield starts the discussion about the pitfalls of creating users from existing users.