Hello,<\/p>\n
I’m trying to write my first PowerShell script. I hope you can help me.<\/p>\n
I receive several emails every day to create a folder, group and add permissions. I would like to make my work easier<\/p>\n
For example:<\/p>\n
20111-New-Project<\/p>\n
I need to create a folder on the server with the same name<\/p>\n<\/li>\n
In AD I have to create a group - 20111_RW<\/p>\n<\/li>\n
Depends who sent me this email, I need to add different members to this group (North, South, East or West)<\/p>\n<\/li>\n
Add this group to the folder with modification permissions<\/p>\n<\/li>\n<\/ol>\n
I have a problem with the point 3<\/p>\n
I would like to define groups as numbers but i don’t know is it possible.<\/p>\n
I don’t even know how to ask Google about it …<\/p>\n
2.South_RW and South_RO,<\/p>\n
3.East_RW and East_RO,<\/p>\n
4.West<\/p>\n
I want PS to ask me what members to add when creating the group.<\/p>\n
Any suggestions how to do this?<\/p>\n
param(\n [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] $Client\n )\n\n$NoProject = $Client.substring(0,5)\n\n$Domain = \"domain.local\"\n$ADPath = \"OU=Test0,OU=Groups,DC=domain,DC=local\"\n$ClientPath = \"\\\\Server\\TEST\\$Client\"\n\n$GroupParams= @{\n 'Name' = \"${NoProject}_RW\" \n 'SamAccountName' = \"$NoProject\" \n 'GroupCategory' = \"Security\"\n 'GroupScope' = \"Global\"\n 'DisplayName' = \"$Client Read-Write Access\"\n 'Path' = \"OU=Test0,OU=Groups,DC=domain,DC=local\"\n 'Description' = \"Members of this group have read-write access to the test share\"\n}\n\nNew-ADGroup @GroupParams\n\n# Check if folder exist, if not create new Client folder\nIf(!(test-path $ClientPath))\n {\n New-Item -Path $ClientPath -ItemType Directory\n\n# Get permissions\n $acl = Get-Acl -Path $ClientPath\n\n# Get Security Groups\n get-adobject -searchbase $ADPath -ldapfilter {(objectclass=group)}\n\n# set new permissions\n $acl | Set-Acl -Path $ClientPath\n }\n<\/code><\/pre>","upvoteCount":6,"answerCount":6,"datePublished":"2022-02-07T19:15:34.000Z","author":{"@type":"Person","name":"tennorbert","url":"https://community.spiceworks.com/u/tennorbert"},"suggestedAnswer":[{"@type":"Answer","text":"Hello,<\/p>\n
I’m trying to write my first PowerShell script. I hope you can help me.<\/p>\n
I receive several emails every day to create a folder, group and add permissions. I would like to make my work easier<\/p>\n
For example:<\/p>\n
20111-New-Project<\/p>\n
\n- \n
I need to create a folder on the server with the same name<\/p>\n<\/li>\n
- \n
In AD I have to create a group - 20111_RW<\/p>\n<\/li>\n
- \n
Depends who sent me this email, I need to add different members to this group (North, South, East or West)<\/p>\n<\/li>\n
- \n
Add this group to the folder with modification permissions<\/p>\n<\/li>\n<\/ol>\n
I have a problem with the point 3<\/p>\n
I would like to define groups as numbers but i don’t know is it possible.<\/p>\n
I don’t even know how to ask Google about it …<\/p>\n
\n- North_RW and North_RO,<\/li>\n<\/ol>\n
2.South_RW and South_RO,<\/p>\n
3.East_RW and East_RO,<\/p>\n
4.West<\/p>\n
I want PS to ask me what members to add when creating the group.<\/p>\n
Any suggestions how to do this?<\/p>\n
param(\n [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] $Client\n )\n\n$NoProject = $Client.substring(0,5)\n\n$Domain = \"domain.local\"\n$ADPath = \"OU=Test0,OU=Groups,DC=domain,DC=local\"\n$ClientPath = \"\\\\Server\\TEST\\$Client\"\n\n$GroupParams= @{\n 'Name' = \"${NoProject}_RW\" \n 'SamAccountName' = \"$NoProject\" \n 'GroupCategory' = \"Security\"\n 'GroupScope' = \"Global\"\n 'DisplayName' = \"$Client Read-Write Access\"\n 'Path' = \"OU=Test0,OU=Groups,DC=domain,DC=local\"\n 'Description' = \"Members of this group have read-write access to the test share\"\n}\n\nNew-ADGroup @GroupParams\n\n# Check if folder exist, if not create new Client folder\nIf(!(test-path $ClientPath))\n {\n New-Item -Path $ClientPath -ItemType Directory\n\n# Get permissions\n $acl = Get-Acl -Path $ClientPath\n\n# Get Security Groups\n get-adobject -searchbase $ADPath -ldapfilter {(objectclass=group)}\n\n# set new permissions\n $acl | Set-Acl -Path $ClientPath\n }\n<\/code><\/pre>","upvoteCount":6,"datePublished":"2022-02-07T19:15:35.000Z","url":"https://community.spiceworks.com/t/create-a-folder-create-a-group-add-to-a-group/824369/1","author":{"@type":"Person","name":"tennorbert","url":"https://community.spiceworks.com/u/tennorbert"}},{"@type":"Answer","text":"Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n