PowerShell creates folders and gives specific users owner permissions

Source: Internet
Author: User

A period of time before a file server migration, where there are many users of redirected folders, such as desktops, documents, pictures, etc.

Because of the large number, the process of repeatedly creating and authorizing each folder is a headache and a script is written

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

#导入账户信息

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

#遍历账户信息

Foreach ($User in $UserName)

{

#在本地创建与用户名相同的文件夹

New-item-path "E:\Userhome ' $"-itemtype directory-name $User

#定义文件夹权限

$Ar = New-object System.Security.AccessControl.FileSystemAccessRule ("contoso\$ ($User)", "FullControl", " Containerinherit,objectinherit "," none "," Allow ")

#修改文件夹权限

$ACL = Get-acl-path "E:\Userhome ' $\$ ($User)"

$Acl. SetAccessRule ($Ar)

Set-acl-path "E:\Userhome ' $\$ ($User)"-aclobject $ACL

}

Complete, now you have a lot of folders that are the same as the account name, and only that user has Full Control permissions ~ ~ ~

PowerShell creates folders and gives specific users owner permissions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.