1

PowerShell 스크립트를 사용하여 드라이브를 사용자에게 자동 매핑하려고했습니다.PowerShell 스크립트로 만든 사용자에게 드라이브를 매핑 할 수없는 이유는 무엇입니까?

스크립트는 명령을 사용하여 사용자 만들기 : 사용자가 생성

New-ADUser -Name $userName -GivenName $userName -Surname $userName -DisplayName $userName -Path "OU=Eng,DC=lovely,DC=Local" -SamAccountName $userName -AccountPassword (ConvertTo-SecureString $pass -AsPlainText -Force) -UserPrincipalName ($userName + '@lovely.local') -Enable $true -HomeDrive 'H:' -HomeDirectory "\\DC01\Private\$userName" 

을하지만 사용자에 로그온 할 때 드라이브가 매핑되지 않은 계정은 "개인"주 안에있는 사용자 폴더 생성되지 않습니다.

은 그럼 수동으로 클라이언트에서 매핑을 시도하고이 오류 메시지가 :

다음과 같은 오류가 발생하여 매핑 된 드라이브가 생성되지 수 없습니다 : 지정된 네트워크 리소스 또는 드라이브가 더 이상 available

그래서 서버 (경로 : C:\Private\user1)에 사용자 폴더를 만들었고 수동으로 매핑 할 수 있습니다.

그래서 나는 드라이브를 분리하고 (AD 사용자 및 컴퓨터   → OU   → 사용자 1   → 프로필) 사용자 프로필 탭을 열고 수동으로 다시 동일한 경로 입력 :

\\DC01\Private\user1 

과를 다시 로그온하면 드라이브가 매핑됩니다!

왜 그런 일이 발생합니까?

는 서버 (2016 기준) 버추얼 박스에서 VM으로 설치됩니다
  • , 클라이언트는 윈도우   8, 또한 VM입니다.
  • Windows 방화벽이 사용되지 않으며 Windows Defender입니다.
  • Windows   8 컴퓨터가 도메인의 구성원입니다.
  • 은 "개인"주 속성 :

    Share permissions "\DC01\Private": Authenticated Users (Full Control)

    NTFS permissions "C:\Private": SYSTEM (Full Control), Administrators (Full Control), CREATOR OWNER (Full Control, subfolders and files only), Authenticated Users (Full Control)

내가 새 사용자를 만들 때 다시 수동으로 매핑 프로세스가 잘 노력하고 있습니다.

전체 스크립트 : Rohin는 Sidharth와 eckes으로

Import-Module ActiveDirectory 

#-----------------# 
# Global Var 
#-----------------# 
$pass = 'Pa$$w0rd' 
$drive_letter = 'H:' 
$dir_path = '\\DC01\Private' 

#-----------------# 
# Eng department 
#-----------------# 
$totalusers = 9 
$uname = "Eng" 
$ou = "Eng" 

for ($i=0; $i -lt $totalusers; $i++) { 
    $userID = "{0:00}" -f ($i + 1) 
    $userName = "$uname$userID" 
    Write-Host "Creating AD user" ($i + 1) "of" $totalusers ":" $userName 
    New-ADUser -Name $userName -DisplayName $userName -Path "OU=$ou,DC=lovely,DC=Local" -SamAccountName $userName -AccountPassword (ConvertTo-SecureString $pass -AsPlainText -Force) -UserPrincipalName ($userName + '@lovely.local') -HomeDrive $drive_letter -HomeDirectory "$dir_path\$userName" -Enable $true 
} 
+0

그것은 소리 그것은 작동합니다. – eckes

+0

어쩌면, 당신은 탭을 사용하고 있지 않습니다, 당신의 질문은 무엇에 관한 것이 아닌가요? – eckes

+1

관련? https://stackoverflow.com/questions/26592223/powershell-homedirectory-not-created-on-fileserver-filesystem –

답변

1

내가 내 스크립트 내 각 사용자에 대한 디렉토리를 만들 때 문제가 해결 주석에 썼다. GUI에는 사용자가 처음 로깅하면 폴더를 만드는 몇 가지 기능이 있습니다.

지금 자신의 홈 폴더를 자동으로

EDIT 볼 수 있습니다 로그온 각 사용자 :

내가 각 부서 디렉토리를 생성하는 루프를 추가합니다.이제 각 사용자는 자신의 디렉토리에만 액세스 할 수 있습니다. 디렉토리 안에 부서 이름이 있습니다 (그리고 부서 사용자 만 디렉토리에 액세스 할 수 있습니다).

foreach ($o in $ous){ 

Write-Host "Creating OU: " $o 
NEW-ADOrganizationalUnit $o 

Write-Host "Create Group $o" 
New-ADGroup -Name "$o" -SamAccountName $o -GroupCategory Security -GroupScope Global -DisplayName "$o" -Path "CN=Users,DC=lovely,DC=local" -Description "$o department" 

# Create department dir 
New-Item -Path "$dir\$o" -ItemType Directory 

$colRights = [System.Security.AccessControl.FileSystemRights]"Read, Write,Traverse" 
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None 
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly 
$objType =[System.Security.AccessControl.AccessControlType]::Allow 
$objUser = New-Object System.Security.Principal.NTAccount("$o") 
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType) 
$objACL = Get-ACL "$dir\$o" 
$objACL.AddAccessRule($objACE) 
Set-ACL "$dir\$o" $objACL 

은} 여기

내가 예를 들어 한 부서의 사용자를 만듭니다

$totalusers = 6 
$uname = "Manager" 
$ou = "Projects" 
for ($i=0; $i -lt $totalusers; $i++) 
{ 
$userID = "{0:00}" -f ($i + 1) 
$userName = "$uname$userID" 
Write-Host "Creating AD user" ($i + 1) "of" $totalusers ":" $userName 

# create user folder inside the share 
CreateUserHomeDir -dir $dir -ou $ou -userName $userName 
New-ADUser -Name $userName -DisplayName $userName -Path "OU=$ou,DC=lovely,DC=Local" -SamAccountName $userName -AccountPassword (ConvertTo-SecureString $pass -AsPlainText -Force) ` 
-userPrincipalName ($userName + '@lovely.local') -Enable $true -HomeDrive $drive_letter -HomeDirectory "$dir_path\$ou\$userName" 


SetDirPermissions -ou $ou -userName $userName -dir $dir 

# add to group 
AddToGroup -groupName $ou -userName $userName 
} 

기능 : 방금 확인하기 위해 폴더를 만들 필요가 같은

function AddToGroup ($groupName, $userName) 
{ 
Add-ADGroupMember $groupName $userName 
} 
function CreateUserHomeDir ($dir, $ou, $userName) { 

New-Item -Path "$dir\$ou\$userName" -ItemType Directory 
} 

function SetDirPermissions ($ou,$userName,$dir) { 
    $colRights = [System.Security.AccessControl.FileSystemRights]"Read, Write,Traverse" 
    $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None 
    $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly 
    $objType =[System.Security.AccessControl.AccessControlType]::Allow 
    $objUser = New-Object System.Security.Principal.NTAccount("$userName") 
    $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType) 
    $objACL = Get-ACL "$dir\$ou\$userName" 
    $objACL.AddAccessRule($objACE) 
    Set-ACL "$dir\$ou\$userName" $objACL 

} 
+0

당신은 당신의 자신의 대답을 받아 들일 수 있습니다. (그리고 당신의 문제를 실제로 풀어 낸 제 의견에 "아니오"라고 말하면 유감입니다.) – eckes

+0

나는 그 실수를 눈치 채지 못했습니다. 나는 그것을 고쳤다. 고마워요. – ic205

+0

그리고 두 번째 댓글에 '아니오'라고 대답했습니다. – ic205