{"id":16231,"date":"2010-12-13T00:01:00","date_gmt":"2010-12-13T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/12\/13\/archiving-file-shares-with-windows-powershell\/"},"modified":"2010-12-13T00:01:00","modified_gmt":"2010-12-13T00:01:00","slug":"archiving-file-shares-with-windows-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/archiving-file-shares-with-windows-powershell\/","title":{"rendered":"Archiving File Shares with Windows PowerShell"},"content":{"rendered":"<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: 10pt\">Summary:<\/span><\/b><span style=\"font-size: 10pt\"> Learn how to use Windows PowerShell to archive file shares.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/><\/span><\/span><\/span><\/span><\/span><\/span>Hey, Scripting Guy! I am interested in using Windows PowerShell to archive file shares, is this something that can be done?<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&#8212; ST<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><span style=\"font-size: 10pt\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/><\/span><\/span><\/span><\/span><\/span><\/span>Hello ST, Microsoft Scripting Guy Ed Wilson here. Welcome to guest blogger week. We welcome back Tibor Soos one of our MVP&rsquo;s in Hungary. To learn more about Tibor and see his first guest blog post please <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/03\/26\/hey-scripting-guy-march-26-2010.aspx\"><span style=\"color: #0000ff\">follow this link<\/span><\/a>. Without further ado, here is Tibor.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">I frequently give on-site presentations for System Administrators and for their managers so that they can discover the great potential of Windows PowerShell and how Windows PowerShell scripts can help them save lots of money and\/or time to reach their operational goals. In this article, I selected one of my favorite examples. <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">The task is archiving data on file shares. File shares are still heavily used and the data on these shares are larger and larger continuously. Backing up this data and making sure that old, &ldquo;historical&rdquo; data is not deleted or modified unintentionally is always challenging. Therefore, I created a script that moves files that were not modified within the last 30 days (by default) from the &ldquo;live&rdquo; data folder or share to a read-only &ldquo;archive&rdquo; folder or share. Meanwhile, I leave a shortcut at the original location which points to the archived copy so that users can still access these files easily. The content of the read-only archive cannot be modified by users. Therefore, it only has to be backed up once after you run this script. This saves backup media and management costs. <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Here is the whole script:<\/span><\/p>\n<p class=\"CodeBlockScreenedHead\" style=\"padding-left: 30px\"><strong>Backup-FileShares.ps1<\/strong><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">param(<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>[Parameter(<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Mandatory = $true,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Position = 0,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>HelpMessage = &#8220;Root of the folders or share to archive&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>)]<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>[String] $source,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>[Parameter(<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Mandatory = $true,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Position = 1,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>HelpMessage = &#8220;Path of the folder or share of archive&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>)]<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>[string] $target,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>[Parameter(<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Mandatory = $false,<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Position = 3<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>)]<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span>[int] $days = 30<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Object created for shortcut creation <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$wsh = new-object -comobject wscript.shell<span>&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Get all the files from the source path, that are not shortcuts and older than the days set<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">Get-ChildItem $source -Recurse |<span>&nbsp;&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Where-Object {!$_.psiscontainer -and ((get-date) &#8211; $_.lastwritetime).totaldays -gt $days -and $_.extension -ne &#8220;.lnk&#8221;} | <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ForEach-Object {<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># For each file build the destination path<span>&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$dest = $_.fullname -replace ([regex]::escape($source)), $target <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Check if the destination file path has the parent directory, if not create it<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$parent = split-path $dest<span>&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>if(!(test-path $parent)){<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>[void] (new-item -Path (split-path $parent) -Name (split-path $parent -leaf) -ItemType directory) <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Save the modification date and the ACL of the file for later use<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$date = $_.lastwritetime<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$acl = $_ | Get-Acl<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Try to move the file into the destination<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Move-Item -Path $_.fullname -Destination $dest -ErrorAction silentlycontinue<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># If successful create shortcut<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>if($?){<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$shortCut = $wsh.CreateShortCut(&#8220;$($_.fullname).lnk&#8221;)<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$shortCut.TargetPath = $dest<span>&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$shortCut.Save()<span>&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Set the &#8220;date modified&#8221; property of the shortcut same as date modified property of the original file<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>(Get-Item &#8220;$($_.fullname).lnk&#8221;).lastwritetime = $date<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Replace the access control entries on the shortcut, so that users have read only access to it<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;<\/span>$acl.SetAccessRuleProtection($true,$true)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$acl | Set-Acl -Path &#8220;$($_.fullname).lnk&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$acl = Get-Item &#8220;$($_.fullname).lnk&#8221; | Get-Acl<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$acl.Access | where-object {&#8220;BUILTIN\\Administrators&#8221; -ne $_.identityreference -and &#8220;NT AUTHORITY\\SYSTEM&#8221; -ne $_.identityreference} | <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ForEach-Object {<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$identity = $_.identityreference<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>[void] $acl.RemoveAccessRule($_) <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>$restrictedACE = New-Object system.security.AccessControl.FileSystemAccessRule($identity,&#8221;ReadAndExecute&#8221;,,,&#8221;Allow&#8221;) <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$acl.AddAccessRule($restrictedACE)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$acl | Set-Acl<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>}<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"># Else write error message<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>else { write-host &#8220;Error moving $_&#8221; -ForegroundColor red}<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">If you save this file as &ndash; for example, <b>Backup-FileShares.ps1<\/b> &ndash; then you can call it from Windows PowerShell as follows:<\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">c:\\your-path-to-the-scriptfile\\Backup-FileShares.ps1 &ndash;source \\\\server1\\path-to-archive -target \\\\server2\\path-of-archive -days 60<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Of course, you have to have the relevant admin rights on both the source server and the target server. You can also use local folder paths instead of UNC share names. I commented the source code, but let&rsquo;s walk through the code so that I can make some additional comments.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">The first section is the parameter definition part. The <i>source<\/i> and the <i>target<\/i> are mandatory. If you omit the <i>days<\/i> parameter, the default value is 30 days.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Next, I define the <b>wscript.shell<\/b> COM object. This helps me to create the shortcuts later. Then I list all the file objects under the source path that were not modified during the last given days and which are not shortcut files.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">With these files, I do a <b>foreach-object<\/b> cycle, in which the first task is to define the new path of the file in the archive:<\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$dest = $_.fullname -replace ([regex]::escape($source)), $target <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">I just replace the source part of the full path of the file with the destination path. As the paths generally include characters that are reserved for regex, I escape them by using the <b>escape<\/b> static method of the <b>Regex<\/b> class of the .NET Framework. This trick is rarely mentioned in Windows PowerShell books and articles but I found it very useful. So when you do not exactly know what you want to find or replace by regex, I recommend always escaping the search string. Here is an example of how it works:<\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">PS C:\\&gt; [regex]::Escape(&#8220;\\\\server\\share\\somefile.ext&#8221;)<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">\\\\\\\\server\\\\share\\\\somefile\\.ext<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">You can see that all problematic characters are escaped automatically.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Next, as I want to place the files into the same folder structure in the archive as the original one, I have to build this structure there. So I define the <b>$parent<\/b> variable to include the path of the parent folder of the archive-file-to-be by the <b>Split-Path<\/b> cmdlet. Then I check whether this folder already exists. If not, then I create it with the <b>New-Item<\/b> cmdlet. Let&rsquo;s stop here for a moment! What happens if the file to be moved to the archive is located in a deep folder hierarchy such as this?<\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">\\\\server1\\share\\mainfolder\\subfolder\\subsubfolder\\thefile.docx<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">If the target is \\\\server2\\share, then the parent folder of the archived file is as follows:<\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">\\\\server2\\share\\mainfolder\\subfolder\\subsubfolder<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">But the parent folder of this folder may not exist yet either! Fortunately, the <b>New-Item<\/b> cmdlet is clever enough to resolve this problem by creating all the necessary folder path elements including all nonexistent folders in the path. But this is true only for directories. Therefore, if you use <i>&ndash;ItemType Directory<\/i> as the parameter, it is not for files! If I want to create a file in a nonexistent folder, <b>New-Item<\/b> will give an error. But for now I do not have to create new files. I&rsquo;m just moving existing ones. <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">If <b>New-Item<\/b> can create the folder successfully, it also gives an output which I&rsquo;m not interested in, so I suppress it by converting the result to <b>[void]<\/b>.<\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: 10pt\">Remark:<\/span><\/b><span style=\"font-size: 10pt\"> There are at least three ways of suppressing output; convert the output to <b>[void]<\/b>, redirect it to <b>$null<\/b> and send it to the <b>Out-Null<\/b> cmdlet through the pipeline. I did an experiment to determine which is the most efficient. I measured the three options by the <b>Measure-Command<\/b> cmdlet, here are the results:<\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">PS C:\\&gt; measure-command {1..1000 | %{$_ &gt; $null}} | Select-Object -ExpandProperty milliseconds<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">238<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">PS C:\\&gt; measure-command {1..1000 | %{$_ | out-null }} | Select-Object -ExpandProperty milliseconds<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">405<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">PS C:\\&gt; measure-command {1..1000 | %{[void] $_}} | Select-Object -ExpandProperty milliseconds<\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">180<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">As you can see the type conversion method is the fastest so I selected this option in my script (not because I really needed that performance benefit here but just to satisfy my engineer self).<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">So we are at the point where there is a parent folder for the file in the archive. Then I save the modification date of the file to be moved into variable <b>$date<\/b> and its access control list into <b>$acl<\/b> for later use, and I try to move the file into the archive. The file may be locked and therefore cannot be moved. I do not want to show the error message, I&rsquo;d rather handle this situation myself, and so I used the <b>silentlycontinue<\/b> error-handling method. I check the <b>$?<\/b> automatic variable, this variable shows the success of the last command.If this is <b>$true<\/b>, then I know that the move was successful. In this case, I first create the shortcut with the <b>wscript.shell<\/b> object that was stored in the variable <b>$wsh<\/b> before. The name of this shortcut is the same as the file name plus an additional extension of .lnk. The shortcut points to the destination path.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">As I want to point users to the original file as much as possible, I set the modification date of the shortcut to the modification date of the original file. This time stamp was stored in variable <b>$date<\/b> before.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">I also want to map the access control on the shortcut to the access control of the original file. I want to enable read access to the shortcut only for those who had any access to the original file, but I do not want to change the access of the System or Administrators accounts. This is the relevant code from the script:<\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$acl.SetAccessRuleProtection($true,$true)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$acl | Set-Acl -Path &#8220;$($_.fullname).lnk&#8221;<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$acl = Get-Item &#8220;$($_.fullname).lnk&#8221; | Get-Acl<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$acl.Access | where-object {&#8220;BUILTIN\\Administrators&#8221; -ne $_.identityreference -and &#8220;NT AUTHORITY\\SYSTEM&#8221; -ne $_.identityreference} | <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">ForEach-Object {<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$identity = $_.identityreference<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>[void] $acl.RemoveAccessRule($_) <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>$restrictedACE = New-Object<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;<\/span><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.security.AccessControl.FileSystemAccessRule($identity,&#8221;ReadAndExecute&#8221;,,,&#8221;Allow&#8221;) <\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$acl.AddAccessRule($restrictedACE)<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">}<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">$acl | Set-Acl<\/span><\/span><\/p>\n<p class=\"CodeBlockScreened\" style=\"padding-left: 30px\"><span style=\"font-size: 10pt\"><span style=\"font-family: Lucida Sans Typewriter\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">First I remove the inheritance flag by calling the <b>SetAccessRuleProtection<\/b> method. With the two <b>$true<\/b> parameters I copy the inherited access control entries as explicit entries. Then I commit these changes by setting this DACL to the shortcut. I need this step, because at this point the access control entries within this DACL still have the <b>IsInherited<\/b> flag set to <b>$true<\/b>. Unfortunately the <b>RemoveAccessRule<\/b> method cannot move these kinds of ACEs and the <b>IsInherited<\/b> property is read-only so this is the easiest way of resetting these ACEs.<\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: 10pt\">Remark:<\/span><\/b><span style=\"font-size: 10pt\"> The <b>RemoveAccessRule<\/b> method does not give any error message when removing ACEs with the <b>IsInherited<\/b> flag on, it even outputs <b>$true<\/b>, indicating that the removal was successful. But when you check the ACEs you will discover that these entries are still there. This strange behavior caused me some headaches.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">I set the <b>$acl<\/b> and re-read it back from the shortcut. Now it includes only explicit ACEs, all with the correct <b>IsInherited<\/b> flags. Then I filter the ACEs by a <b>where-object<\/b>, because I do not want to change the System and Administrator access. For all the other ACEs I save the user or group to <b>$identity<\/b>, remove the ACE and put a replacement back for the same identity with a <b>ReadAndExecute<\/b> entry. Finally, I set the new ACE to the shortcut object again.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Actually, this is it. If the file move was unsuccessful, then I write a message on the console.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">The following figures detail the user experience. These are the files here before archiving:<\/span><\/p>\n<p class=\"Num-Caption\"><span style=\"font-size: x-small\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7317.HSG-12-13-10-01.jpg\" border=\"0\" \/><\/span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">And this figure shows the directory after archiving:<\/span><\/p>\n<p class=\"Num-Caption\"><span style=\"font-size: x-small\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0250.HSG-12-13-10-02.jpg\" border=\"0\" \/><\/span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">As you can see, the files that were older than 30 days are replaced by shortcuts. The Date modified column contains the same dates for the shortcuts as the original files. The icons are almost the same.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Let&rsquo;s analyze the archive location now as seen in the following figure:<\/span><\/p>\n<p class=\"Num-Caption\"><span style=\"font-size: x-small\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8255.HSG-12-13-10-03.jpg\" border=\"0\" \/><\/span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">It has all the archived files and the same folder structure as the original data share.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">This figure gives us a view the file permissions on the shortcuts:<\/span><\/p>\n<p class=\"Num-Caption\"><span style=\"font-size: x-small\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5315.HSG-12-13-10-04.jpg\" border=\"0\" \/><\/span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">As you can see the permissions include explicit permissions only, and even the <strong>ModifyGroup<\/strong> that has modify permissions on the original file, has read &amp; execute permissions now.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Of course, the script can be developed further to make adjustments to the access control list of the archive, but it is already useful in this form.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">If you liked this post and need some help creating scripts, you can contact me by email:<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: 10pt\">Tibor So&oacute;s<\/span><\/b><span style=\"font-size: 10pt\"> (<a href=\"mailto:soost@IQJB.hu\"><span style=\"color: #0000ff\">soost@IQJB.hu<\/span><\/a>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">Windows PowerShell MVP<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\"><a href=\"http:\/\/www.iqjb.hu\/\"><span><span style=\"color: #0000ff\">www.IQJB.hu<\/span><\/span><\/a><\/span><\/p>\n<p class=\"Num-Caption\"><span style=\"font-size: x-small\">&nbsp;<\/span><span style=\"font-size: x-small\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">ST, that is all there is to using Windows PowerShell to archive file shares.<span>&nbsp; <\/span>Thank you Tibor, for your time and for sharing your knowledge with us. Guest blogger week will continue tomorrow when we will have Trevor Sullivan talk about dynamic method invocation. <\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\"><span style=\"color: #0000ff\">Twitter<\/span><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\"><span style=\"color: #0000ff\">Facebook<\/span><\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\"><span style=\"color: #0000ff\">scripter@microsoft.com<\/span><\/a> or post them on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\"><span style=\"color: #0000ff\">Official Scripting Guys Forum<\/span><\/a>. See you tomorrow. Until then, peace.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: 10pt\">Ed Wilson, Microsoft Scripting Guy<\/span><\/b><span style=\"font-size: 10pt\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; Summary: Learn how to use Windows PowerShell to archive file shares. &nbsp; Hey, Scripting Guy! I am interested in using Windows PowerShell to archive file shares, is this something that can be done? &#8212; ST &nbsp; Hello ST, Microsoft Scripting Guy Ed Wilson here. Welcome to guest blogger week. We welcome back Tibor Soos [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,3,185,12,75,45],"class_list":["post-16231","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-scripting-guy","tag-shared-folders-and-mapped-drives","tag-storage","tag-tibor-soos","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp;&nbsp; Summary: Learn how to use Windows PowerShell to archive file shares. &nbsp; Hey, Scripting Guy! I am interested in using Windows PowerShell to archive file shares, is this something that can be done? &#8212; ST &nbsp; Hello ST, Microsoft Scripting Guy Ed Wilson here. Welcome to guest blogger week. We welcome back Tibor Soos [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=16231"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16231\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=16231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}