Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need to delete a file from folder which is sample_YYYYMM.zip file.

$
0
0

Could any one help me with the below code which i have tried. We are new to powershell. 

$Path = "E:\backup"
$ZipTimestamp = Get-Date -format YYYYMM;
$MonthsBack = "-12"
$CurrentMonth = Get-Date.Month
$DatetoDelete = $ZipTimestamp + $CurrentMonth.Month($MonthsBack)
Get-ChildItem $Path -Recurse -include *_YYYYMM.zip | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>