Srijani Ghosh
Srijani Ghosh

Reputation: 4216

Powershell : This operation returned because the timeout period expiredAt

I am trying to run xTestPlan_1.ps1 from enable_local.ps1.

While enable_local.ps1 is on my local machine, xTestPlan_1.ps1 is on network drive. I only have the shortcut to xTestPlan_1.ps1 on my local machine.

Here is enable_local.ps1:

$item = "d:\temp\xTestPlan_1.lnk"
WriteInLogFile "$item"
Try
{
    & "$item"
}
Catch
{
    WriteInLogFile $Error
}

While running this code, sometimes, I get this error:

Program "xTestPlan_1.lnk" failed to run: This operation returned because the timeout period expired At D:\Temp\enable_local.ps1.

This script sometimes works as expected, sometimes it does not work. xTestPlan_1.ps1 does exist on the network drive.

Upvotes: 1

Views: 920

Answers (1)

henrycarteruk
henrycarteruk

Reputation: 13227

Trying to execute a shortcut isn't a good way to run another script.

A better to do this is to call the script directly:

$item = "\\server\share\xTestPlan_1.ps1"
WriteInLogFile "$item"
Try
{
    & $item
}
Catch
{
    WriteInLogFile $Error
}

If you really must use a shortcut for some reason, you can get the target path from the shortcut and then call the script itself.

$item = "d:\temp\xTestPlan_1.lnk"

$ShellObj = New-Object -COM WScript.Shell
$targetPath = $ShellObj.CreateShortcut($item).TargetPath

WriteInLogFile "$targetPath"
Try
{
    & $targetPath
}
Catch
{
    WriteInLogFile $Error
}

Upvotes: 2

Related Questions