我正在尝试在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 :