Hi, I have made a script which move all monthly report to a specific folder after creating a new folder of the current month in “yyyy-MM” format. For example if it runs on 30th April, it will create a new folder “2018-APR” and then move all files there. The requirement is to run this script at the last day of every month but in our application, we don’t have any option to select last day, instead we can select a specific date. The problem is if we select 30th of every month, what will happen in the months with 31 days or feb? So we are planning to run it on 1st of every month but folder name should be of previous month. Means, if we are running the script on 1st of May, it should also create folder “2018-APR”. I am currently using following string:
New-Item -ItemType Directory -Path “$folder1$(Get-Date -Format yyyy)$(Get-Date -Format yyyy-MMM)” -Force
Get-ChildItem -File -Path “$folder2” | Move-Item -Destination “$folder1$(Get-Date -Format yyyy)$(Get-Date -Format yyyy-MMM)”
I have tried “$(get-date).adddays(-1) -format yyyy-MM” string but it’s not working. Can someone help?