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.
I want to be able to move the employee to the same OU as the user I will be copying permissions from.
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.
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.
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.
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?
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.