Is it possible to pass a CIM Session to a job, or to call it from a job somehow? The big benefit to using CIM over WMI is being able to open a session, allowing you complete multiple calls while only requiring one single handshake.[br]
Here is what I tried, but it of course did not work…[br]
$Session = New-CimSession -ComputerName $Computer -SessionOption $Option[br] [br] $sb = {[br] Param ($Session)[br] Get-CimInstance -Query "SELECT * FROM Win32_UserProfile" -CimSession $Session | Sort-Object -Property LastUseTime -Descending | Select-Object -First 1[br] }[br] [br] $j = Start-Job -ScriptBlock $sb -ArgumentList $Session[br] Wait-Job $j -Timeout 15 | Out-Null[br] [br] $LastUser = $j | Receive-Job[br] $j | Remove-Job[br] [br] $clientHealth.LastUser = $($LastUser.LocalPath -replace [regex]::escape('C:\Users\'),'')
[br]
I also tried passing the computer name and then calling the session in line like "-CimSession (Get-CimSession $Computer) ", but that didn’t work either. [br]
A quick Google search came back with nothing, so I am pretty confident that this is a dead end, but I figured it couldn’t hurt to pose the question to you guys. Pretty sure I am not the first to try this.