title: Single PowerShell Script to Create Folder, AD Groups, and Apply New Groups to Folder
body: <p>I'm wanting to:</p>
  
  <ul>
  <li>Create New Folder</li>
  <li>Set Share Name for folder so that users can see it</li>
  <li>Create AD Group FS-TESTSHARE-R</li>
  <li>Create AD Group FS-TESTSHARE-RW</li>
  <li>Apply Both groups to the new share folder</li>
  <li>Set Full Read permissions to FS-TESTSHARE-R</li>
  <li>Set Full Read/Rights permissions to FS-TESTSHARE-RW</li>
  <li>Set full access permissions to Domain Admins</li>
  </ul>
  
  <p>Here is what I have now after playing around a little bit, but I wanted to make sure I didn't miss anything. I've decided (for the time being to leave out the param settings, but I can come back to that later.  Does this look correct or is there a better way to write the script?</p>
  
  <p>I've also ran into a bunch of errors about unexpected </p>
  
  <pre><code>New-ADGroup 
      -Name "FS-$NAME-RW" 
      -SamAccountName "FS-"+$NAME+"-RW" 
      -GroupCategory Security 
      -GroupScope Global 
      -DisplayName "$NAME Read-Write Access" 
      -Path "CN=$LOCATION,CN=SECURITY GROUPS,CN=FILE SHARE GROUPS,DC=ESG,DC=INTL" 
      -Description "Members of this group have read-write access to the test share"
  
  New-ADGroup 
      -Name "FS-$NAME-R" 
      -SamAccountName "FS-"+$NAME+"-R" 
      -GroupCategory Security 
      -GroupScope Global 
      -DisplayName "$NAME Read Access" 
      -Path "CN=$LOCATION,CN=SECURITY GROUPS,CN=FILE SHARE GROUPS,DC=ESG,DC=INTL"
      -Description "Members of this group have read access to the test share"
  
  
  # create new folder
  New-Item -Path $Path -ItemType Directory
  
  # get permissions
  $acl = Get-Acl -Path $Path
  
  #Get Security Groups
  get-adobject -searchbase "CN=SECURITY GROUPS,CN=FILE SHARE GROUPS,DC=ESG,DC=INTL" -ldapfilter {(objectclass=group)}
  
  # add a new permission
  $acl.SetAccessRuleProtection($True, $False)
  
  $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
  $acl.AddAccessRule($rule)
  
  $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("esg.intl\Domain Admins","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
  $acl.AddAccessRule($rule)
  
  $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("esg.intl\"FS-"+$NAME+"-R"","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
  $acl.AddAccessRule($rule)
  
  $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("esg.intl\"FS-"+$NAME+"-RW"","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
  $acl.AddAccessRule($rule)
  
  # set new permissions
  $acl | Set-Acl -Path $path
  </code></pre>
  
  <p>I'm also running into some errors and I'm not sure I understand how to fix them...</p>
  
  <pre><code>At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:44 char:96
  + ... " -ldapfilter {(objectclass=group)}
  +                    ~
  Use `{ instead of { in variable names.
  At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:55 char:82
  + ... ule("esg.intl\"FS-"+$NAME+"-R"","FullControl", "ContainerInherit, ObjectInherit" ...
  +                    ~~~~~~~~~~~~~~~~
  Unexpected token 'FS-"+$NAME+"-R""' in expression or statement.
  At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:55 char:82
  + ... ule("esg.intl\"FS-"+$NAME+"-R"","FullControl", "ContainerInherit, ObjectInherit" ...
  +                    ~
  Missing closing ')' in expression.
  At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:55 char:164
  + ... "None", "Allow")
  +                    ~
  Unexpected token ')' in expression or statement.
  At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:58 char:82
  + ... ule("esg.intl\"FS-"+$NAME+"-RW"","FullControl", "ContainerInherit, ObjectInherit ...
  +                    ~~~~~~~~~~~~~~~~~
  Unexpected token 'FS-"+$NAME+"-RW""' in expression or statement.
  At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:58 char:82
  + ... ule("esg.intl\"FS-"+$NAME+"-RW"","FullControl", "ContainerInherit, ObjectInherit ...
  +                    ~
  Missing closing ')' in expression.
  At C:\Users\A-Shane.Johnson\Desktop\ShareFolderCreation.ps1:58 char:165
  + ... "None", "Allow")
  +                    ~
  Unexpected token ')' in expression or statement.
      + CategoryInfo          : ParserError: (:) [], ParseException
      + FullyQualifiedErrorId : OpenBraceNeedsToBeBackTickedInVariableName
  </code></pre>