How to create destination folder with date appended to it via Powershell?

  powershell, sysadmin, windows

I have backup files sitting in a directory. The objective I am trying to achieve is that each time I run this piece of Powershell against that directory, I want it to move the files into a folder that gets created and append today’s date to it. I have tried this:

Get-ChildItem -Path 'C:APIAPIBackups' | ForEach-Object {
    Move-Item -Path $_.FullName -Destination "C:UsersAdminDesktopNew folder$($_.BaseName,(Get-Date).ToString("MMddyyyy"),$_.Extension)"
}

All this does is moves the backup files into "New folder" and append the date to the files themselves. I’m wanting it to create a new folder with today’s date appended within "New folder" and have the backup files sitting in there. Any help would be great.

Source: Windows Questions

LEAVE A COMMENT