Trying to move files with specific file names from root directory to a subfolder
- by Justin Reagan
Hi I'm still pretty new to powershell so I apologize if I ask something that extremely basic. I have a root directory on a tftp server that pulls down config files from routers and other equipment every night. The files are like this IPaddress_YYYYMMDD_TA5000. There is a limitation in the equipment where the files can't be set to move into the root directory on their own.
What I want to do is make a powershell script that will only move the files with the TA5000 part in the filename to the sub directory and only keep the 5 most recent files.
I looked but I couldn't seem to find what I would need to do to parse the file for that specific string. I already have the portion of the script to delete the files based on age that was simple.
Any help on getting started would be appreciated.
Edit: I forgot to post the code I was trying.
Move-Item c:\tftptransferfiles c:\tftptransferfiles\sca | Where-Object {_.name -like "*TA5000*"}
I keep getting a error saying that the item at C:\tftptransferfiles is in use.