user6015403
user6015403

Reputation:

Drive Mapping Incorrect when AD User created with Powershell

I have written a script that works great.. It creates user accounts, sets password, places in correct OU, creates home drive folder and sub folders within it. Users are able to login and have no issues however one thing that i have noticed is that users are mapping to a difference drive from the one specified in AD. Script block for this is:

$homedrivepath = "Server_Path_for_users_data"
$homedrive = "Y"

New-ADUser -HomeDirectory "$homedrivepath" -HomeDrive "$homedrive"

As i mentioned, everything else works just fine. This issue is that even in AD, it shows as Y being drive letter but when users login, it maps them to Z: instead. Any ideas why this can be happening? It isn't managed by a GPO or anything like that either.

Thank You!

Upvotes: 0

Views: 1409

Answers (3)

Mark Francis
Mark Francis

Reputation: 11

I was having this issue with drives mapping as Z: I create new users using a vb.net windows application and i had homedrive as M instead of M:

This has fixed my issue!! So the same applied to vb.net as did powershell.

Upvotes: 1

tata
tata

Reputation: 1

You should write:

$homedrive = "Y:"

Instead of:

$homedrive = "Y"

Upvotes: 0

DisplayName
DisplayName

Reputation: 1016

do you have any other script? check if its messing around.

Test this script makes ad creation easy. https://gallery.technet.microsoft.com/scriptcenter/Create-AD-user-on-the-go-3b754198

Import-Module activeDirectory 
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null  
$Firstname = [Microsoft.VisualBasic.Interaction]::InputBox("Enter firstname ") 
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null  
$Lastname = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Lastname ") 
$PWD=[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null  
$PWD= [Microsoft.VisualBasic.Interaction]::InputBox("Enter Password ") 
$dnsroot = '@' + (Get-ADDomain).dnsroot 
$OU="CN=users, DC=Domain,DC=COM" 
$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow 
    #$Sam=$User.FirstName+$User.LastName example john snow will be Johnsnow 
    #$Sam=$User.FirstName example john snow will be John 
    #$Sam= $User.firstName + "." + $User.lastName example john snow will be John.snow 
$Dname="$firstName " + "$lastName" 
$UPN = $Sam + “$dnsroot” 
New-ADUser -Name "$firstName $lastName" -DisplayName $Dname -AccountPassword (ConvertTo-SecureString “$pwd” -AsPlainText -force) -GivenName $FirstName  -Path $OU -SamAccountName $SAM -Surname $LastName  -UserPrincipalName $UPN -Enabled $TRUE 
Write-Output "User $Firstname has been created" -foregroundcolor Green 
## setting up stuff## 
$user=$sam 
Write-Host "Would you like to set up Home Drive?"        -ForegroundColor Green 
$Response = Read-Host "[Y] Yes, [N] No" 
    If($Response -eq "y") 
{Get-ADUser $user | % { Set-ADUser $_ -HomeDrive "H:" -HomeDirectory ('\\SERVER\home$\' + $_.SamAccountName) }} 


#now create Home folder# 


    if( -not ( Test-Path \\server\home$\$User ) ){ 
        New-Item -Path \\server\home$\$User -ItemType directory 
        } 


#**** setting up Login script* 
Write-Host "Would you like to add Login Script?"        -ForegroundColor Green 
$Response = Read-Host "[Y] Yes, [N] No" 
    If($Response -eq "y") 
{Get-ADUser $user | Set-ADUser -ScriptPath 'yyy.bat'} 


## add to group## 
Write-Host "allow to add to group Group?"        -ForegroundColor Green 
$Response = Read-Host "[Y] Yes, [N] No" 
    If($Response -eq "y") 
 {Add-ADGroupMember -Identity Group -Member $user} 
 write-host "Sit back and relax all task has been completed"        -ForegroundColor Green

Upvotes: 0

Related Questions