Can I automate these files with a script?

On my company’s shared drive there is a folder called FOLDERNAME. In that folder there is a subfolder called FILES. I need a script that will check for the existence of a folder named CURRENTMONTH.YEAR

i.e. if it ran today it would be looking for a folder named October.2020. If it doesn’t find the folder then it creates one. Then it should copy all the files with a creation date that matches the month and year and moves them from the source folder to the current month folder.

I’m very new to powershell and I don’t even know where to begin with something like this, or if it’s even something I can do with a script. Any ideas or leads for me?

@amay012704 - Welcome to the world of Powershell.

Some of the commands that you will need to be familiar with is the Get-Command and Get-Help cmdlets.

You can use wildcards to search for a command that may work for what you are trying to accomplish. For example: Get-Command copy or Get-Help copy

Also outline what the process will entail.

  • Get contents of a share drive folder "FILES" - Look into Get-ChildItem = Get-Help Get-ChildItem -full
    • Create condition to search for folder CURRENTMONTH.YEAR folder
      • If (condition is true) {
        • Move files to current month folder}
        • Else {
          • Create folder - Look into New-Item = Get-Help New-Item
            • Then Copy files unto new folder}
Just a quick summary of what your process may involve but of course it's however you see fit; What I've learned is that there are numerous ways to achieve a result. Really no wrong way if we leave out the Powershell ethics. ;)

Hope that helps is some way.

 

 

This code might help you get started with checking for the folder and creating if it does not exist. Change $FileLocation to a valid path.

$Date = Get-Date
$FileLocation = “\SERVER\SHARE\FOLDERNAME\FILES”
$AryMonths = @(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”)
$CurrentFolder = Join-Path $FileLocation “$($AryMonths[$Date.Month - 1]).$($Date.Year)”

If (!(Test-Path $CurrentFolder)) {
New-Item -ItemType Directory -Path $CurrentFolder | Out-Null
}