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