Jump to content

Anbody have Reddit unblocked can mirror some info for me? (Also New-ADUser issues)


Recommended Posts

Posted (edited)

New AD-User script defaulting users' homedir to Z: : PowerShell

 

I'm having some issues with homedrives.. I've made a script that creates student accounts..

} else {
New-ADUser `
	-SamAccountName $UserName `
	-UserPrincipalName $UserPrincipalName `
	-Name $UserName `
	-DisplayName $UserName `
	-GivenName $Forename `
	-Surname $Surname `
	-Description "Pupil" `
	-EmailAddress $UserPrincipalName `
	-HomeDrive "M" `
	-HomeDirectory $HomeDirectory `
	-Path $Path `
	-ProfilePath "$ProfilePath" `
	-AccountPassword (ConvertTo-SecureString "Password" -AsPlainText -force) `
	-Enabled $True `
	-ChangePasswordAtLogon $True
}

and as far as the account in AD is concerned, if I check the 'Profile' tab, it does show 'Connect M: To: \\FileServer\Pupils\$Username' as it should do. And when a kid logs in, the drive is mapped.. \\FileServer\Pupils\$Username is mapped as a drive.. But to Z:, not to M:. Google-fu is letting me down as lots of people seem to want to use Z: as their drives so not getting a whole lot of results. Google's preview shows

28 Jul 2014 - So I created a script that creates new ad user, assigns properties to the ... Everything works on paper, except when I actually log in it gives the Z: drive to the homedir, not H:. .... set-aduser -Identity $un -homedrive $homedr.
so it looks to be a discussion on what I need, but it's blocked upstream at the LEA (with good reason, in all fairness..) so I can't get to it.

 

Edit: And my phone gets no signal here :(

Edited by Garacesh
Posted

Here is our powershell for new-ADUser

New-ADUser -Name $Student.Username `
                      -SamAccountName $Student.Username `
                      -GivenName $Student.Forename `
                      -Surname $Student.LastName `
                      -DisplayName ($Student.Forename + " " + $Student.LastName) `
                      -UserPrincipalName ($Student.Username + "@schoolname.sch.uk") `
                      -Path ("OU=" + $Student.YoE + ",OU=Students,OU=XXX,OU=Establishments,DC=XXX,DC=internal") `
                      -EmailAddress ($Student.Username + "@schoolname.sch.uk") `
                      -Office "Student" `
                      -Department $Student.TutorGroup `
                      -AccountPassword (ConvertTo-SecureString -AsPlainText $Student.DoB -Force) `
                      -ProfilePath ("\\XXX-US-01\" + $Student.Username + "$\Profile") `
                      -HomeDrive "N:" `
                      -HomeDirectory ("\\XXX-US-01\" + $Student.Username + "$\Documents") `
                      -Enabled $true

Posted

Here's a copy of it, seems like someone had the answer but for some reason has deleted their response! The OP even seem to say it was the answer:

 

New AD-User script defaulting users' homedir to Z: (self.PowerShell)

submitted 7 months ago by Kerackiswhack

So I created a script that creates new ad user, assigns properties to the user, dumps into the proper OU, assigns groups, then creates the homedir. Everything works on paper, except when I actually log in it gives the Z: drive to the homedir, not H:. I am explicit on using H: and it even shows in AD. My work around is to assign it a different letter, apply, then assign it back. Then everything works. Any ideas?

Script (edited for security):

Create new AD user

 

import-module activedirectory

Input variables

 

$first = read-Host 'First Name' $last = read-Host 'Last Name' $Description = read-host 'Title?' $Office = read-Host 'Department?' $Manager = read-Host 'Manager? (CN=Manager,OU=Users,OU=Department,DC=########)' $Phone = read-Host 'Phone Number?' $Fax = read-Host 'Fax number?' $un = read-Host 'Username?' $pw = Read-Host -AsSecureString 'Password?'

Static variables

 

$Name = $first + ' ' + $last $username = $un + '########' $logon = '########' $homedr = 'H' $Homedir = '\########\vol1\users\' + $un $address = '########' $company = '########' $City = '########' $Zip = '########' $State = '########'

----------------------------------------------------------------------------------------------

 

Invoke script

 

new-ADUser $name -Enabled $true -AccountPassword $pw -City $City -Company $company -Country US -Department $Office -Description $Description -DisplayName $name -Fax $Fax -HomeDirectory $Homedir -Manager $Manager -Office $Office -PostalCode $Zip -ScriptPath $logon -State $State -StreetAddress $address -Title $Description -OfficePhone $Phone -SamAccountName $un -UserPrincipalName $username -GivenName $first -Surname $last -Confirm

sleep 5

Provision AD group memberships and move user to correct OU

 

if ($Office -eq 'Community Impact') {add-ADGroupMember 'Staff' -Members $un; add-ADGroupMember 'Community Impact' -Members $un; add-ADGroupMember 'sg_CommInvest' -Members $un; Get-ADUser $un | Move-ADObject -TargetPath 'OU=Users,OU=########,DC=########'} elseif ($Office -eq 'Development') {add-ADGroupMember 'Staff' -Members $un; add-ADGroupMember 'Investor Relations Workplace' -Members $un; add-ADGroupMember 'sg_Campaign' -Members $un; Get-ADUser $un | Move-ADObject -TargetPath 'OU=Users,OU=Development,DC=########'} elseif ($Office -eq 'Executive') {add-ADGroupMember 'Staff' -Members $un; add-ADGroupMember 'Executive' -Members $un; add-ADGroupMember 'sg_Executive' -Members $un; Get-ADUser $un | Move-ADObject -TargetPath 'OU=Users,OU=Executive,DC=########'} elseif ($Office -eq 'Finance') {add-ADGroupMember 'Staff' -Members $un; add-ADGroupMember 'Finance' -Members $un; add-ADGroupMember 'Finance and Administration' -Members $un; add-ADGroupMember 'sg_Finance' -Members $un; Get-ADUser $un | Move-ADObject -TargetPath 'OU=Users,OU=Finance,DC=########'} elseif ($Office -eq 'Investor Relations') {add-ADGroupMember 'Staff' -Members $un; add-ADGroupMember 'Investor Relations Major Gifts' -Members $un; add-ADGroupMember 'Investor Relations Workplace' -Members $un; add-ADGroupMember 'sg_MajorGifts' -Members $un; Get-ADUser $un | Move-ADObject -TargetPath 'OU=Users,OU=########,DC=########'} elseif ($Office -eq 'Marketing') {add-ADGroupMember 'Staff' -Members $un; add-ADGroupMember '`Marketing' -Members $un; add-ADGroupMember 'sg_Marketing' -Members $un; Get-ADUser $un | Move-ADObject -TargetPath 'OU=Users,OU=Marketing,DC=########'}

Sleep 5

----------------------------------------------------------------------------------------------

 

Create home directory

 

$path = '\########\vol1\users\' $Homedir2 = '\########\vol1\users\' + $un

new-item -path $path -name $un -ItemType directory

Set ACL

 

$ACL = Get-Acl "$homedir2" $ACL.SetAccessRuleProtection($true, $false)

$ACL.Access | ForEach { [Void]$ACL.RemoveAccessRule($_) } $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("########","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))) $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))) $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("########","Modify", "ContainerInherit, ObjectInherit", "None", "Allow"))) Set-Acl "$homedir2" $ACL

Sleep 5

Map drive letter to home directory

 

set-aduser -Identity $un -homedrive $homedr

2 commentssharesavehidegive goldreport

all 2 comments

sorted by: top

[–][deleted] 7 months ago*

[deleted]

[–]Kerackiswhack 2 points 7 months ago

Now I feel like a retard. I didn't think it mattered because in AD it showed as the H:, even though I didn't use a colon. Thanks for the quick help for an idiot PS user :)

permalinksavegive gold

[–]Kerackiswhack 1 point 7 months ago

I also want to add, the final block shows me giving the user the letter drive, I originally had that in the New-ADUser line but put at the end for testing. "Same result"

permalinksavegive gold

Posted

Well I know our users are getting N: mapped as we've been using this script for a couple of years now.

 

I did notice that in the example of yours, you did not have the : after the drive letter in the -HomeDrive value, so it's not actually assigning a letter correctly so will use Z as "M" doesn't exist, whereas "M:" does

Posted

Oh bummer.. Looks like that colon makes all the difference..

 

Odd that it should still show in AD as M: then, but fail.. Bizarre. But thank you.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...