Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Copy a .txt file with a variable in the title to another folder

I have a simple ping script that produces an output file at the end to a local folder, the file name contains a variable that pulls the host name of the computer its run on and adds it to the file name. I then want to be able to move this file to another file path but wasn’t how to do with the variable names .txt file.

$H = hostname 

cd c:/users 

ping ipaddress -n 4 |Foreach{"{0} - {1}" -f (Get-Date),$_} > chosenfolder\$H"DC1!".txt

Any help would be appreciated.

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Tried using the basic copy-item cmdlet but this didn’t work.

>Solution :

If all you are after is to move the file then you can you the mv command in powershell.

$H = hostname 

cd c:/users 

ping ipaddress -n 4 |Foreach{"{0} - {1}" -f (Get-Date),$_} > chosenfolder\$H"DC1!".txt

mv chosenfolder\$H"DC1!".txt C:\<whatever path>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading