Let's say we have a folder with a number of sub folders, in each sub folder there is a different number of folders named after years start and end date. All folders contain a different set of "year folders".
for example:
C:\Test\A\20050101-20051231
C:\Test\A\20060101-20061231
C:\Test\A\20070101-20071231
C:\Test\B\20140101-20141231
C:\Test\B\20150101-20151231
C:\Test\B\20160101-20161231
C:\Test\C\20090101-20091231
C:\Test\C\20100101-20101231
C:\Test\C\20110101-20111231
I need help with creating a powershell script that searches through these folders and then move the root folder, in this example "C:\A", that doesn't have any year folder from 2009 to 2016. Unfortunately I can't use time stamps.
Tried a start with this but it will just exclude the subfolders from the result.
Get-ChildItem -Depth 1 | ?{ $_.PSIsContainer } | where {$_.name -notlike "2013"}| Select-Object FullName
Thanks
This would work if the folder structure is always the same.
Returns a file system object for each folder that doesn't have a year between 2009 and 2016, add
| Remove-Item -Recurse
next to the last}
to remove the folders.Edit:
Changed it up a little. Using theNevermind that was all sorts of wrong. Just switch toName
parameter forGet-ChildItem
and switching the sides of the inner where statement so we can use thelike
operator with a wild card appended to the name.FilterScript
to use theSubString()
method.