0
我試圖在PowerShell中複製一個文件,並同時放置一個datestamp。這如何在Powershell中正確使用變量作爲Copy-Item的目標參數?
$localfiles = @(Get-ChildItem -File $PSScriptRoot)
Foreach ($i in $localfiles)
{
$date = Get-Date
#write-host $i
if (!(Test-Path @("Z:\Desktop\" + $i)))
{
Copy-Item $i "Z:\Desktop\"
#Add-Content backuplog.txt "[" Get-Date "]" " initalized file " $i
Write-Host "[$date] Uploaded Z:\Desktop\"$i
} else {
$newpath = @("Z:\Desktop\[$date]" + "$i")
Copy-Item $i -Destination "$newpath"
#Write-Host "incremented $newname"
#Add-Content backuplog.txt "[" Get-Date "]" " incremented file " $i
}
}
返回
The given path's format is not supported.
的寫主機返回
[01/11/2015 12:33:55] Uploaded Z:\Desktop\ System.Object[]
我嘗試了一些類型轉換的(的ToString),沒有一次成功。任何提示?
Windows上的文件名不能包含斜槓或冒號。試試不包含那些日期格式? –
謝謝,這是一個愚蠢的開始 – jamesson