我有一個簡單的 ping 腳本,它在本地檔案夾的末尾生成一個輸出檔案,檔案名包含一個變數,該變數會提取運行它的計算機的主機名并將其添加到檔案名中。然后我希望能夠將此檔案移動到另一個檔案路徑,但不是如何處理變數名 .txt 檔案。
$H = hostname
cd c:/users
ping ipaddress -n 4 |Foreach{"{0} - {1}" -f (Get-Date),$_} > chosenfolder\$H"DC1!".txt
任何幫助,將不勝感激。
謝謝
嘗試使用基本的 copy-item cmdlet,但這不起作用。
uj5u.com熱心網友回復:
如果您所追求的只是移動檔案,那么您可以使用mvpowershell 中的命令。
$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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/527285.html
標籤:电源外壳
上一篇:如何在遠程會話中設定區域變數?
