<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx</link><description>Summary: Learn how to use Windows PowerShell to archive file shares. 
 
 Hey, Scripting Guy! I am interested in using Windows PowerShell to archive file shares, is this something that can be done? 
 -- ST 
 
 Hello ST, Microsoft Scripting Guy Ed</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx#3557623</link><pubDate>Sat, 09 Mar 2013 22:30:02 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3557623</guid><dc:creator>bahman62</dc:creator><description>&lt;p&gt;hi scripting guy,&lt;/p&gt;
&lt;p&gt;i use this script to archive &lt;/p&gt;
&lt;p&gt;----&lt;/p&gt;
&lt;p&gt;param(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[Parameter(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mandatory = $true,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Position = 0,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HelpMessage = &amp;quot;Root of the folders or share to archive&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;)]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[String] $source,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[Parameter(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mandatory = $true,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Position = 1,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HelpMessage = &amp;quot;Path of the folder or share of archive&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;)]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[string] $target,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[Parameter(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Mandatory = $false,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Position = 3&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;)]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[int] $days = 30&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;# Object created for shortcut creation &lt;/p&gt;
&lt;p&gt;$wsh = new-object -comobject wscript.shell &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Get-ChildItem $source -Recurse | &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Where-Object {!$_.psiscontainer -and $_.extension -eq &amp;quot;.xla&amp;quot; -and ((get-date) - $_.lastwritetime).totaldays -gt $days -and $_.extension -ne &amp;quot;.lnk&amp;quot;} | &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ForEach-Object {&lt;/p&gt;
&lt;p&gt;# For each file build the destination path &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$dest = $_.fullname -replace ([regex]::escape($source)), $target &lt;/p&gt;
&lt;p&gt;# Check if the destination file path has the parent directory, if not create it&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$parent = split-path $dest &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(!(test-path $parent)){&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[void] (new-item -Path (split-path $parent) -Name (split-path $parent -leaf) -ItemType directory) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;# &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$date = $_.lastwritetime&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$acl = $_ | Get-Acl&lt;/p&gt;
&lt;p&gt;# Try to move the file into the destination&lt;/p&gt;
&lt;p&gt;		ls $_.fullname &amp;gt;&amp;gt; c:\logs\test1.txt&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Move-Item -Path $_.fullname -Destination $dest -ErrorAction silentlycontinue&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;----&lt;/p&gt;
&lt;p&gt;then i start it with the file &amp;nbsp;rolle.pa1 file &amp;nbsp;like.\Backup-FileSharesm.ps1 -source C:\logs -target C:\archive -days 30&lt;/p&gt;
&lt;p&gt;How can i say when you find a folder then if exist rolle.ps2 then read the rolle from rolle.ps2 for archive otherwise is default from rolle.ps1&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3557623" width="1" height="1"&gt;</description></item><item><title>re: Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx#3557529</link><pubDate>Fri, 08 Mar 2013 21:51:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3557529</guid><dc:creator>Aida</dc:creator><description>&lt;p&gt;Greate scripts Thanks&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3557529" width="1" height="1"&gt;</description></item><item><title>re: Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx#3513702</link><pubDate>Fri, 10 Aug 2012 16:54:49 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3513702</guid><dc:creator>IamMred</dc:creator><description>&lt;p&gt;@Mikko Koskenkorva What you will want to do is to modify the code a bit to capture the original timestamps, and then write them to the copied files. Take a look at this Hey Scripting Guy blog article I wrote last week &lt;a rel="nofollow" target="_new" href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/04/weekend-scripter-use-powershell-to-set-word-document-time-stamps.aspx"&gt;blogs.technet.com/.../weekend-scripter-use-powershell-to-set-word-document-time-stamps.aspx&lt;/a&gt; &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3513702" width="1" height="1"&gt;</description></item><item><title>re: Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx#3513646</link><pubDate>Fri, 10 Aug 2012 12:37:26 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3513646</guid><dc:creator>Mikko Koskenkorva</dc:creator><description>&lt;p&gt;Hi Scripting guy, great post! Exactly what I was looking for and works a charm :) Any hints how to retain the archived folders&amp;#39; Created date value or Date modified value? The files keep the original date stamps but since folders are created when the script is run they&amp;#39;re assigned fresh values.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d need to be able to track down the archived items by the date abd the folder dates are in crucial role in this operation.&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Mikko&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3513646" width="1" height="1"&gt;</description></item><item><title>re: Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx#3495012</link><pubDate>Fri, 27 Apr 2012 20:14:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3495012</guid><dc:creator>Any reason yet...  </dc:creator><description>&lt;p&gt;Get the same thing - any reason why? &amp;nbsp;- Is this because it&amp;#39;s a Windows 2003 source with a Windows 2008 R2 destination? &amp;nbsp;Is there an issue with archiving across the network? &amp;nbsp;(other than speed). &amp;nbsp;Would it be faster if it were on the same box - would it work without the error NC discussed?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3495012" width="1" height="1"&gt;</description></item><item><title>re: Archiving File Shares with Windows PowerShell</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/13/archiving-file-shares-with-windows-powershell.aspx#3379347</link><pubDate>Mon, 10 Jan 2011 18:59:40 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3379347</guid><dc:creator>NC</dc:creator><description>&lt;p&gt;The script &amp;quot;works&amp;quot; for the most part. There is a link created, and the file is archived. However, I get the following error on every single file:&lt;/p&gt;
&lt;p&gt;Set-Acl : The security identifier is not allowed to be the owner of this object.&lt;/p&gt;
&lt;p&gt;At C:\Documents and Settings\johndoe\My Documents\Backup-FileShares.ps1:56 char:35&lt;/p&gt;
&lt;p&gt;+ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $acl | Set-Acl &amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;nbsp;-Path &amp;quot;$($_.fullname).lnk&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidOperation: (F:\Shared_Files... 1 clip.mov.lnk:String &lt;/p&gt;
&lt;p&gt; &amp;nbsp; ) [Set-Acl], InvalidOperationException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Comma &lt;/p&gt;
&lt;p&gt; &amp;nbsp; nds.SetAclCommand&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3379347" width="1" height="1"&gt;</description></item></channel></rss>