I recently showed a VBScript to Archive/Move xml files to a subfolder.  This is often needed when you have been archive or storing 1000s of XML files, and the the directory/folder is very slow to open due to the large number of files.  Now, we will do it in Powershell.

Create the subfolders ahead of time. With some minor improvements we could do that in the code, but I was in a hurry today when I needed this…

Get-ChildItem "201604*.xml" | ForEach { move -path $_ -destination ($_.directoryname +"\Archive\2016_04\"+ $_.Name)}

This does the following:
1) Select all files starting with “201604” (in my case, the files began with yyyymmdd.
2) pipe that into a ForEach loop
3) Run the “Move” commandlet
4) the filename in the loop is the $_ symbol
5) Then you build the destination directory $_ again is the iterator of the loop, i.e. the FileName object, so we can get it’s directory and “Name”. There, we insert the 2016_xx for the month.

So yes, you can make this a lot fancier, but it’s a start…

Filed under: Powershell