Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PowerShell creates folders and grants Owner permissions to specific users

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report