I have this PSSession which returns the Date from a Remote System. Start-Session is a function which collects Host,User and Password and starts a PSSession. $return is the returnvalue
# Start Session
$Session = Start-Session
# Start Commands in Session
$return = Invoke-Command -Session $Session -Scriptblock {
Get-Date
}
$return
# Close Session
Remove-PSSession $Session
If I put the snippet above into a runspace, $Data is empty.
$Runspace = [runspacefactory]::CreateRunspace()
$PowerShell =[Powershell]::Create()
$PowerShell.runspace = $Runspace
$Runspace.Open()
[void]$PowerShell.AddScript({
# Start Session
$Session = Start-Session
# Start Commands in Session
$return = Invoke-Command -Session $Session -Scriptblock {
Get-Date
}
$return
# Close Session
Remove-PSSession $Session
})
$AsyncObject = $PowerShell.BeginInvoke()
$Data = $PowerShell.EndInvoke($AsyncObject)
$Data
$PowerShell.Dispose()
Is this construction possible ? If yes were do I have to look for the returnvalues? At the PSSession or at the runspaceobject ?
thanks in advance.
regards
Dirk