我正在尝试在 powershell 中运行以下步骤,该步骤会出错。该文件正在被复制,所以我很想用 Force 和 ErrorAction SilentlyContinue 来解决它。但是为什么会这样呢?无论 Force 标志如何,也无论目标位置中是否存在文件,它都会发生。
请注意,所有位置都是 UNC 路径。添加了一些可能会有所作为的额外部分(?)。
$ROOTPATH = "\\servera\sharea"
$STAGEDIR = "$ROOTPATH\submit"
#sample file for $flagfl:
#-rw-rw-r-- 1 mname data 588573 Aug 31 14:51 file16083101.000.Z
$newfiles = get-content $ROOTPATH\$FLAGFL | foreach {$_.split(" ")[8]}
foreach ($thisfile in $newfiles) {
$thisfile_unc=($thisfile).Replace('.Z','')
$reccnt = (Get-Content $ROOTPATH\$thisfile_unc | Measure-Object -line).Lines
$orionfile = "$thisfile_unc.$reccnt"
get-content $ROOTPATH\$thisfile_unc |% {$_.replace("`n", "`r`n")} | out-file -encoding ascii -filepath $ROOTPATH\$orionfile -Force
copy-item $ROOTPATH\$orionfile $STAGEDIR -force
}
错误信息:
copy-item : The operation completed successfully.
At line:1 char:1
+ copy-item $ROOTPATH\$orionfile $STAGEDIR -force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
请求的完整错误消息 () :
Exception : System.IO.IOException: The operation completed successfully.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean
overwrite, Boolean checkHost)
at System.IO.FileInfo.CopyTo(String destFileName, Boolean overwrite)
at Microsoft.PowerShell.Commands.FileSystemProvider.CopyFileInfoItem(FileInfo file, String
destinationPath, Boolean force)
at Microsoft.PowerShell.Commands.FileSystemProvider.CopyItem(String path, String
destinationPath, Boolean recurse)
at System.Management.Automation.SessionStateInternal.CopyItem(CmdletProvider
providerInstance, String path, String copyPath, Boolean recurse, CmdletProviderContext context)
TargetObject :
CategoryInfo : NotSpecified: (:) [Copy-Item], IOException
FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails :