Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell:此操作返回,因为超时时间已过期_Powershell_Powershell 5.0 - Fatal编程技术网

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
}

“有时,我得到了这个错误”是否意味着有时它会像预期的那样工作?很抱歉误解了。是的,它的意思是,有时它工作得很好,有时它不能像预期的那样工作。