Get the App
SLTechnology News&Howtos  ›  Servers  › 

PowerShell creates folders and grants Owner permissions to specific users

Shulou Source: shulou.com Published: 2022-06-02 05:49:49 09月28日 Update

Some time ago, I experienced a file server migration, in which there were many users' redirected folders, such as desktops, documents, pictures, etc.

Because of the large number, the process of repeated creation and authorization of each folder is very troublesome, so a script is written.

First of all, fill in the user name ~ ~ in a document, that is, the account name of the user for whom we want to create a folder

# Import account information

$UserName = Get-Content D:\ UserName.txt

# traversing account information

Foreach ($User in $UserName)

{

# create a folder locally that is the same as the user name

New-Item-Path "E:\ Userhome` $"-ItemType Directory-Name $User

# define folder permissions

$Ar = New-Object System.Security.AccessControl.FileSystemAcce***ule ("Contoso\ $($User)", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")

# modify folder permissions

$Acl = Get-Acl-Path "E:\ Userhome` $\ $($User)"

$Acl.SetAcce***ule ($Ar)

Set-Acl-Path "E:\ Userhome` $\ $($User)"-AclObject $Acl

}

Done, now you have a lot of folders with the same account name and only the user has full control.

Tags: Files folders users permissions same information accounts documents user names accounts headaches that is pictures quantity time server desktop script process control Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Xiaomi Linux Shulou Information