Mirroring file permissions with Powershell

Claus Munch on Aug 22, 2022 · 1 min read

Mirroring file permissions with Powershell

Ever had the situation, that a set of database files doesn't have the right permissions after a restore (maybe to another server) via. eg. Veeam? Powershell to the rescue! 

$SOURCE = 'F:\SQLData\mydb.mdf'
$DESTINATION = 'F:\SQLData\myrestoreddb.mdf'
$PERMISSIONS = Get-Acl -Path $SOURCE 
Set-Acl -AclObject $PERMISSIONS -Path $DESTINATION 


This will take the file permissions from your $SOURCE file and set them on your $DESTINATION file. Nice, easy, Powershell ;)

About the author

Claus Munch has been working with SQL Server in all versions, since 2001. For more than 10 years, he has been running the national SQL Server usergroup. Claus is currently employed by Miracle 42, since 2020.