-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomeFolderCreate.ps1
27 lines (27 loc) · 1.48 KB
/
homeFolderCreate.ps1
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
Import-Module ActiveDirectory
#Указываем общий сетевой ресурс
$Dir = "\\domain.local\profiles$"
#Указываем имя домена
$Domain = "domain.local"
#Получаем в переменную $Users пользователей для которых необходимо провести модификацию
$Users = Get-ADGroupMember -Identity "Domain Users"
foreach ($User in $Users) {
# Складываем каждый необходимый параметр в переменную
$User = $User.sAMAccountName
#Создаем директорию с именем пользователя
$Path = "$Dir\$User"
If(!(Test-Path $Path))
{
New-Item -ItemType Directory -Path $Dir -Name $User
New-Item -ItemType Directory -Path $Dir\$User -Name .telegram
#Устанавливаем права на папку
$ACL = Get-Acl $Path
$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule($User, "DeleteSubdirectoriesAndFiles, Write, ReadAndExecute", "ContainerInherit, ObjectInherit", "None", "Allow")
$ACL.SetAccessRule($AccessRule)
Set-Acl -Path $Path -AclObject $ACL
}
$ACL = Get-Acl $Path
$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule($User, "DeleteSubdirectoriesAndFiles, Write, ReadAndExecute", "ContainerInherit, ObjectInherit", "None", "Allow")
$ACL.SetAccessRule($AccessRule)
Set-Acl -Path $Path -AclObject $ACL
}