title: Changing share permissions using Powershell
body: <p>I'm trying to modify the share permissions of share drives on a bunch of windows servers which are running either 2008 R2 or 2012.</p>
  
  <p>I worked up a script which you can find here:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>Import-Module ActiveDirectory
  
  $list = Get-ADComputer -Filter 'SamAccountName -like "*FP*"' | Select -Exp Name
  
  foreach ($Computer in $list)   
  { 
      Grant-SmbShareAccess -Name User -CimSession Server -AccountName "username" -AccessRight Full -confirm:$false
      $acl = (Get-Item \\$Computer\d$\User ).GetAccessControl('Access')
      $rule = New-Object System.Security.AccessControl.FileSystemAccessRule ("Corp\uc4serv","FullControl","ContainerInherit, ObjectInherit","None","Allow")
      $acl.AddAccessRule($rule)
      Set-Acl \\$Computer\d$\User $acl
      Write-Host -ForegroundColor DarkGreen "Permissions granted on $Computer"
  }
  Write-Host -ForegroundColor DarkBlue "Command Has Completed" 
  </code></pre>
  
  <p>But it doesn't work on 2008 servers presumably because they can't run the Get-SmbShareAccess cmdlet. </p>
  
  <p>What I'm trying to do is very similar to this post here: <a href="https://stackoverflow.com/questions/25663997/how-to-set-share-permissions-on-a-remote-share-with-powershell">How to set share permissions on a remote share with Powershell?</a> but specifically on Windows servers.</p>
  
  <p>I also found this code on a website (<a href="http://windowsitpro.com/powershell/managing-file-shares-windows-powershell" rel="nofollow noreferrer">http://windowsitpro.com/powershell/managing-file-shares-windows-powershell</a>):</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$acl = Get-Acl `
      \\servername\c$\Users\username\sharetest
  $permission = "corp\uc4serv","FullControl","Allow"
  $accessRule = New-Object `
      System.Security.AccessControl.FileSystemAccessRule `
      $permission
  $acl.SetAccessRule($accessRule)
  $acl |
      Set-Acl \\servername\c$\Users\username\sharetest
  </code></pre>
  
  <p>But this just sets the Security on the share instead of the share permissions.</p>
  
  <p>I also looked into using the Net Share command but in order to change share permissions with that, it has to delete and re-create the share drive completely.</p>