-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-UserFolder.ps1
More file actions
41 lines (31 loc) · 1.23 KB
/
New-UserFolder.ps1
File metadata and controls
41 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Function New-UserFolder
{
Param (
[String]$username
)
if ($username -eq $null)
{
Write-Host "To create a new user folder enter the six letter username from ADX. This doesn't need the AD\ on the start. " -ForegroundColor Yellow
$username = Read-Host -Prompt "Enter Username"
}
if ($username.Length -ne 6)
{
Write-Host "Entered username is not six characters long. Are you sure this is correct? (Y/N)" -ForegroundColor Red -BackgroundColor Black
$overide = Read-Host
if ($overide -ne "Y")
{
Write-Host "Abort - Exiting" -ForegroundColor Yellow
Return
}
}
$DomainUsername = "AD\" + $username
$folder = New-Item -ItemType Directory -Path D:\Shares\Users -Name $username
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($DomainUsername, "FullControl", "Allow")
$ACL = Get-Acl $folder
$ACL.SetOwner([System.Security.Principal.NTAccount] $DomainUsername)
$ACL.AddAccessRule($AccessRule)
Set-Acl -Path $folder -AclObject $ACL
$ACL.SetAccessRuleProtection($true, $true)
Set-Acl -Path $folder -AclObject $ACL
explorer.exe $folder
}