Powershell:此操作返回,因为超时时间已过期
我正在尝试从Powershell:此操作返回,因为超时时间已过期,powershell,powershell-5.0,Powershell,Powershell 5.0,我正在尝试从启用本地.ps1运行xTestPlan\u 1.ps1 当enable_local.ps1在我的本地计算机上时,xTestPlan_1.ps1在网络驱动器上。在本地计算机上,我只有到xTestPlan_1.ps1的快捷方式 这里是启用\u local.ps1: $item = "d:\temp\xTestPlan_1.lnk" WriteInLogFile "$item" Try { & "$item" } Catch { WriteInLogFile $Er
启用本地.ps1
运行xTestPlan\u 1.ps1
当enable_local.ps1
在我的本地计算机上时,xTestPlan_1.ps1
在网络驱动器上。在本地计算机上,我只有到xTestPlan_1.ps1
的快捷方式
这里是启用\u local.ps1
:
$item = "d:\temp\xTestPlan_1.lnk"
WriteInLogFile "$item"
Try
{
& "$item"
}
Catch
{
WriteInLogFile $Error
}
运行此代码时,有时会出现以下错误:
程序“xTestPlan_1.lnk”无法运行:此操作返回
因为超时时间在D:\Temp\enable_local.ps1处过期
此脚本有时按预期工作,有时不工作
xTestPlan_1.ps1
确实存在于网络驱动器上。尝试执行快捷方式不是运行其他脚本的好方法
更好的方法是直接调用脚本:
$item = "\\server\share\xTestPlan_1.ps1"
WriteInLogFile "$item"
Try
{
& $item
}
Catch
{
WriteInLogFile $Error
}
如果出于某种原因确实必须使用快捷方式,可以从快捷方式获取目标路径,然后调用脚本本身
$item = "d:\temp\xTestPlan_1.lnk"
$ShellObj = New-Object -COM WScript.Shell
$targetPath = $ShellObj.CreateShortcut($item).TargetPath
WriteInLogFile "$targetPath"
Try
{
& $targetPath
}
Catch
{
WriteInLogFile $Error
}
“有时,我得到了这个错误”是否意味着有时它会像预期的那样工作?很抱歉误解了。是的,它的意思是,有时它工作得很好,有时它不能像预期的那样工作。