1

See below a simplified version of my PowerShell code.

$cred = Import-Clixml d:\cred.xml
Invoke-Command -ComputerName $computer -Authentication Credssp -Credential $cred -InDisconnectedSession -SessionOption @{OutputBufferingMode="Drop";IdleTimeout=2147483647} -Scriptblock {
    $start_job = Start-Job -Scriptblock {
        foreach ($user in $list) {
            $a = Get-ChildItem -LiteralPath $user -Recurse -Force
            Write-Output "$a.Count" | Out-File c:\test.log -Append
    } -ArgumentList $list
}

I would send a list of maybe 30 names but after a few minutes of scanning the operations would stop without any error reported, it seems as if the Start-Job is blocked or suspended as the Invoke-Command is still running. any idea on how to check or bypass this limitation?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
JET
  • 11
  • 1
  • 3
    Fix your code. `$list` is not defined, "$a.count" won't print the count, change it to "$($a.count)". Wrap `Get-ChildItem` in the `@()` array operator, otherwise you might receive `$null` from `Get-ChildItem`. – Moerwald May 18 '19 at 07:05
  • 1
    Also, the `foreach` is missing a closing curly bracket. – Ansgar Wiechers May 18 '19 at 13:15

0 Answers0