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
}
Get-ChildItem
to/sitecore/media library
, as searchingmaster:\
, otherwise it will have to enumerate the ENTIRE content tree (including templates, renderings, all of the content, etc.)