我是PowerShell的新手,已经阅读了许多类似的问题。对于我想做的事情,答案似乎很复杂。我想:
下面的代码是我想出的,但是显然不起作用。我在PowerShell ISE中遇到的错误是:
copy-item:路径中的非法字符。
在\ TheMappedDrive \ Share \ AllDepts \ OneDept \ VerifyLogsMove.ps:2 char:1
copy-item testVerifyLog.xlsm- 目的地'\ TheMappedDrive \ Share \ AllDepts \ OneDept ...
CategoryInfo:未指定:(:) [Copy-Item],ArgumentException
FullyQualifiedErrorID: System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand
Set-Location \\TheMappedDrive\Share\AllDepts
copy-item testVerifyLog.xlsm -destination '\\TheMappedDrive\Share\AllDepts\OneDept\Copies of Logs\testVerifyLog ; testVerifyLog-$(((get-date).ToUniversalTime()).ToString("yyyyMMdd")).xlsm'
这样的东西
$curDate = Get-Date -Format yyyyMMdd
$destinationFolder = '\\TheMappedDrive\Share\AllDepts\OneDept\Copies of Logs\testVerifyLog'
$destinationFile = Join-Path $destinationFolder -ChildPath ('testVerifyLog_' + $curDate + '.xlsm')
copy-item '\\TheMappedDrive\Share\AllDepts\testVerifyLog.xlsm' -destination $destinationFile