Hi. How to pass output from PSsession to $richtextbox1.Appendtext.
Below is the code. I am trying to pass the output hostname to $richtextbox1.Appendtext
$buttonHostname_Click = { $richtextbox1.Clear() $Servers = $textbox1.lines.Split("`n") Foreach ($Server in $Servers) { Get-PSSession | Remove-PSSession $richtextbox1.AppendText("$Server : `n") Try { $MySession = New-PSSession -ComputerName $Server } Catch { $richtextbox1.SelectionColor = "#FF0000" $richtextbox1.AppendText("Fail`n") Continue } Finally { $Error.Clear() } $MyCommands = { $hostname = hostname $richtextbox1.AppendText("$hostname`n") } Invoke-Command -Session $MySession -ScriptBlock $MyCommands -ErrorAction Stop } }