3

I am running the following script using SPE Remoting (trying to find all images on all sitecore sites, but this doesn't matter as it is off subject for this post):

Import-Module -Name SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://sitecorehostname

$script = {Get-ChildItem -Path "master:\" -Recurse | Where-Object { $_.Extension -match "png" -or $_.Extension -match "jpg" -or $_.Extension -match "bmp"}}

$TheStuff = Invoke-RemoteScript -Session $session -ScriptBlock $script 

Write-Host $TheStuff

Stop-ScriptSession -Session $session

This gives me a timeout error:

Exception calling "ExecuteScriptBlock2" with "5" argument(s): "The operation has timed out" At \Documents\WindowsPowerShell\Modules\SPE\Invoke-RemoteScript.ps1:257 char:13 + $response = $singleConnection.Proxy.ExecuteScriptBlock2($ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException

If I run the same script in the Sitecore Powershell SPE, it runs fine and returns 4413 records.

The httpRuntime setting in my Sitecore root Web,config is:

<system.web>
        <httpRuntime maxRequestLength="512000" executionTimeout="3600" enableKernelOutputCache="false" relaxedUrlToFileSystemMapping="true" requestValidationMode="4.0" enableVersionHeader="false" />
</system.web>

So that timeout is at 60 minutes. This script times out in 102 seconds.

Is there a way to increase the timeout, or am I invoking an incorrect script?

Edit:

Here is how I implemented the code, based on the answer below:

Import-Module -Name SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://sitecorehostname
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
        # This may make the code easier to maintain.
        $extensions = @("jpg", "png", "bmp")
        #Get-ChildItem -Path "master:/media library" -Recurse | Where-Object { $_.DisplayName -eq "CoveoFacet"}
        Get-ChildItem -Path "master:\media library" -Recurse | Where-Object { $extensions -contains $_.Extension } | Select-Object -Property Name, Id, TemplateName
} -AsJob
$results = Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 5 -Verbose
Stop-ScriptSession -Session $session

ForEach($result in $results)
{
    Write-Host $result.Name
    Write-Host $result.Id
    Write-Host $result.TemplateName
    Write-Host $newline
}
3
  • One thought, you probably want to restrict Get-ChildItem to /sitecore/media library, as searching master:\ , otherwise it will have to enumerate the ENTIRE content tree (including templates, renderings, all of the content, etc.) Commented Aug 3, 2017 at 17:08
  • Is it at all possible that there may be image files in the rest of the tree, outside of the media library directory? Commented Aug 3, 2017 at 17:49
  • I would be surprised if there was. Generally the media library is where media items would be stored. Commented Aug 3, 2017 at 18:23

2 Answers 2

4

You'll want to make use of the Wait-RemoteScriptSession command. A more ideal scenario than increasing the web.config timeout is to simply poll the server for updates. Another idea after discussing could be that the timeout occurs because there is a significant amount of data serialized and returned by the service. The example filters to a few properties using Select-Object.

Import-Module -Name SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri https://remotesitecore
$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
        # This may make the code easier to maintain.
        $extensions = @("png","jpg","bmp")
        Get-ChildItem -Path "master:\media library" -Recurse | Where-Object { $extensions -contains $_.Extension } | Select-Object -Property Name, ID, TemplateName
} -AsJob
Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 5 -Verbose
Stop-ScriptSession -Session $session
1
  • This is the answer, with no changes to the timeout in the root web.config. I am going to edit the Question to show how I implemented the code. Commented Aug 3, 2017 at 20:14
3

I think that you are changing timeout wrong web.config.

Try to change it in web.config located here:

sitecore modules\PowerShell\Services\web.config

3
  • Where do I add the timeout attribute in this file? Can you put an example of the file's contents in your answer? Commented Aug 3, 2017 at 17:53
  • @crackedcornjimmy same place where you did it in Sitecore root Web.config. system.web>httpRuntime
    – Anton
    Commented Aug 4, 2017 at 7:44
  • 1
    I tried that and it exploded with massive fireworks. Commented Aug 7, 2017 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.