Archive files to a folder

Welcome Forums General PowerShell Q&A Archive files to a folder

This topic contains 3 replies, has 2 voices, and was last updated by

6 months, 3 weeks ago.

  • Author
  • #97371


    Hi, I have created a script which generates the domain controller inventory in csv format on daily basis and name it same as the current date. For example, if we are running it today, the name would be "DC_29032018.csv". I am using powershell cmdlets for ARS server (QADUser). At the end of the month we have 28, 30 or 31 files according to the month.

    Now I want to move all the csv files generated to a folder called "Archive" at the same path once the month ends. I am able to do it on daily basis but not able to automate it on the basis of month end as some month has 30 days and some has 31. Can someone guide where I am doing mistake?

  • #97377


    You could run a once a month script that gets the files in that folder and moves them to a specified folder

    New-Item -Path "C:\Temp\$(Get-Date -Format yyyyMM)" -ItemType Directory
    Get-ChildItem C:\Temp -File | Move-Item -Destination "C:\Temp\$(Get-Date -Format yyyyMM)"
  • #97383


    Can we include this in current script?

  • #97389


    For sure, test by running something non destructive 1st so you can set the scheduled task without breaking anything then tailor it to your needs.

The topic ‘Archive files to a folder’ is closed to new replies.