Archive files to a folder

This topic contains 3 replies, has 2 voices, and was last updated by  Alex Aymonier 3 weeks, 6 days ago.

  • Author
    Posts
  • #97371

    Nilabh Verma
    Participant

    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

    Alex Aymonier
    Participant

    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

    Nilabh Verma
    Participant

    Can we include this in current script?

  • #97389

    Alex Aymonier
    Participant

    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.

You must be logged in to reply to this topic.