I’m working on a reporting script right now to determine employee utilization of an enterprise application, Box Sync (like a commercial implementation of Dropbox). It’s crucial that I get this to run with Invoke-Command for parallelization because we have so many endpoints to test against. I don’t have logic in here yet to deal with systems not powered on, but in preliminary testing it’s working great against my local machine but failing with a wsmanfault when I try to run it against another local machine on the domain.
[CmdletBinding()] Param( [Parameter(Mandatory=$True,Position=1)] [string[]]$ComputerName='localhost' ) Invoke-Command -ComputerName $ComputerName -AsJob -JobName BoxCheck -ScriptBlock { $exepresent = Test-Path "$env:ProgramFiles\Box\Box Sync\BoxSync.exe" $exerunning = [bool] (Get-Process | Where-Object {$_.ProcessName -eq "BoxSync"}) $explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue) $usernames = @() if ($explorerprocesses.Count -eq 0){ $logonstatus = "Nobody logged on" #currently not using this variable } else { $logonstatus = "User(s) logged on" #currently not using this variable foreach ($i in $explorerprocesses){ $username = $i.GetOwner().User $usernames += $username } } foreach ($user in $usernames) { $boxsyncdirectoryexists = Test-Path "$env:SystemDrive\Users\$user\Box Sync" $boxsyncdirectorystats = If ($boxsyncdirectoryexists) { Get-ChildItem -Path "$env:SystemDrive\Users\$user\Box Sync" -Recurse -Force -ErrorAction SilentlyContinue } $boxsyncdirectorysize = [math]::Round( ( ( $boxsyncdirectorystats | Measure-Object -Property Length -Sum).Sum / 1MB ),2 ) $properties = @{ComputerName = $env:COMPUTERNAME BoxSyncInstalled = $exepresent BoxSyncRunning = $exerunning User = $user BoxDatainMB = $boxsyncdirectorysize SyncDirExist = $boxsyncdirectoryexists} $obj = New-Object -TypeName PSObject -Property $properties Write-Output $obj } } Get-Job 'BoxCheck' #| Wait-Job
The error:
Processing data for a remote command failed with the following error message: For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OperationStopped: ($computername:String) [], PSRemotingTransportException + FullyQualifiedErrorId : JobFailure + PSComputerName : $computername
I’ve already run
set-item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048
to increase the memory. It was already set at 1024 previously. If I had to guess, it is failing during the Get-ChildItem command. It shouldn’t be a very big file list anyway, even though it’s recursive. People don’t typically dump a lot of files into their synced folder to begin with.
Let’s say it is the GCI command though. I want to be able to handle a large file list. How do I ensure that I always have enough memory to run this? Set an absurdly high memory limit? I don’t need to return the results of the GCI command over the remoting session, it’s only included so that I can calculate the size of the combined files and folders in that directory. I could really use some tips. Thanks!