PowerShell Script to easily copy a file and rename in new destination

Sharing with you a simple Powershell script I wrote and use to generate a .TXT that will list all the file names/location in myfolder A and then easily copy that TXT file from myfolder A in drive A into myfolder B in drive B. It can be used for other file types as well.

For copying between remote servers, you will have to make a few modification to the script – this article from MS can guide you :- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-6

$From = “K:\myfolderA\listofusersinthisfolder.txt”
Get-ChildItem K:\myfolderA\*.*| Set-Content K:\myfolderA\listofusersinthisfolder.txt
Copy-Item -Path $From -Destination “J:\myfolderB\newlistofusers.txt” -Recurse -Force

$From = This will be the full path of the file you want to copy

-Destination = This will be the destination drive and folder for your copied file