Powershell – How to export shared folder with permissions and groups associated


I'm working on a windows server 2008 r2 and I'm trying to export the configuration of shared folder with all the groups associated to them,permissions and file system permissions.

is there a way to do that?

maybe with powershell?

@edit: another problem is that I need to do that after a reboot, so I have to save the configuration in a file for example and then reimport it.

Best Solution

If you want to backup/restore all existing shares you could export/import the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares.


reg export HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares shares.reg


reg import shares.reg
net stop server && net start server

File/folder ACLs can be saved and restored like this:


Get-WmiObject -Class Win32_Share -Filter 'Type = 0' | select -Expand Path | % {
  $path = $_
  Get-Acl $path | select @{n='Path';e={$path}}, Sddl
} | Export-Csv 'C:\path\to\acls.csv'


Import-Csv 'C:\path\to\acls.csv' | % {
  $acl = Get-Acl $_.Path
  Set-Acl -Path $_.Path -AclObject $acl
Related Question