Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a folders based on username and set permissions to them

Status
Not open for further replies.

mikedazzle99

Technical User
Jun 22, 2022
1
NL
Need assistance with a Powershell script for automatically creating X and Y folders
The folders to be created have the following path

\\pathA
\\pathB


Looking to create a powershell script that takes the username as an input parameter, and executes the following file system operations
Create the user-folder \\home\homeshare\<username>
The user should have write access within these folders



Came up with this thus far but i am looking to have the input just the manual entered in and have the folders paths created based of this with the need acls.

Code:
#variables
$user = read-host "input username"
$path = read-host "input path"

#create the directory
new-item -Path $directory -name $username -ItemType directory


$NTPrinciple=[system.security.principal.ntaccount]$username

$permission=New-Object system.security.accesscontrol.filesystemaccessrule($NTPrinciple,'FullControl','Allow',$true,$true)
$acl = Get-Acl $path
$acl.SetAccessRule($permission)
Set-Acl $directory $acl






Any help with having the code generate the path based of the username instead of the manual one below
 
So what part of your process isn't working as you want?


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top