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

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #97371

    Participant
    Topics: 5
    Replies: 3
    Points: 1
    Rank: Member

    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

    Participant
    Topics: 6
    Replies: 115
    Points: 101
    Helping Hand
    Rank: 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

    Participant
    Topics: 5
    Replies: 3
    Points: 1
    Rank: Member

    Can we include this in current script?

  • #97389

    Participant
    Topics: 6
    Replies: 115
    Points: 101
    Helping Hand
    Rank: 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.

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

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort