Implicit remoting returned in text

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
PS_Ross
Posts: 58
Joined: Thu Mar 01, 2018 7:46 am

Implicit remoting returned in text

Post by PS_Ross » Tue Oct 29, 2019 10:13 am

I am running a background job to retrieve some data. When I call upon that data later in my program to load it into a multi-line text box, it seems to include information about the remoting session. I can't seem to find a way to remove it. Screen shot listed below.

https://1drv.ms/u/s!AgBAbImA7NSlyy_5PHr ... Z?e=lYS0Cr

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Implicit remoting returned in text

Post by jvierra » Tue Oct 29, 2019 10:25 am

You have to explicitly select the properties you want or "Exclude" the properties you don't want.

User avatar
PS_Ross
Posts: 58
Joined: Thu Mar 01, 2018 7:46 am

Re: Implicit remoting returned in text

Post by PS_Ross » Tue Oct 29, 2019 10:31 am

To the best of my knowledge I thought I was already doing that. I have a table created, and I am calling that table like so...

$Table.Description

As the description column is the specific one I am interested in for this case.

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Implicit remoting returned in text

Post by jvierra » Tue Oct 29, 2019 10:47 am

Without the code is it hard to know what your issue is. Have you pulled the results and inspected them at a consol?

User avatar
PS_Ross
Posts: 58
Joined: Thu Mar 01, 2018 7:46 am

Re: Implicit remoting returned in text

Post by PS_Ross » Tue Oct 29, 2019 11:06 am

I debugged it a bunch of times, hovering over the table variable to see where the bogus text get's inserted, but I am not able to find it. Here is the short of it, I'll try to keep it simple and explainable.. Let me know if anything else is required, I'll gladly provide it..

DISCLAIMER: I understand you may do things differently as a coder, I am not looking for advice on how to re-approach my methods, although any given is appreciated. The below code works correctly 100% of the time. In this scenario, I am just looking for a way to remove the bogus text I originally posted about.

This is the code for the background job

Code: Select all

$session = New-PSSession -ConnectionUri "https://sfbpool.domain.com/ocsPowerShell" -Credential $global:UserCred
Import-PSSession $session -AllowClobber
                                                                
$Table = [PSCustomObject]([Ordered]@{
                'Description' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Description
                'Name' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Name
                'Managers' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Managers
                'Members' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Members
})
This is the code for the CompletedScript portion of the job

Code: Select all

CompletedScript = {
                Param ($Job)
                $results = Receive-Job -Job $Job
                                                                                                
                $global:RoomData = $results
}
I then call $global:RoomData.Description into my text box in another form, that is when I notice the bogus text about the implicit remoting session.

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Implicit remoting returned in text

Post by jvierra » Tue Oct 29, 2019 11:22 am

This would be the correct way to get what you are looking for:

Code: Select all

$session = New-PSSession -ConnectionUri "https://sfbpool.domain.com/ocsPowerShell" -Credential $global:UserCred
Import-PSSession $session -AllowClobber
                                                                
Get-CsPersistentChatRoom -Identity $global:RoomName | 
        Select-Object Description,Name,Managers,Members

Note that you cannot reference variables outside of a job. You must pass them into the job as an argument.

User avatar
PS_Ross
Posts: 58
Joined: Thu Mar 01, 2018 7:46 am

Re: Implicit remoting returned in text

Post by PS_Ross » Tue Oct 29, 2019 11:44 am

That would work if I was running the code in the foreground, but I am running it in a background job, so I need to pull it back from the job somehow right? That is why I assign each property in a table like I posted above. I need to be able to call each property on it's own, which I am able to do as of now, it just so happens to include that bogus text that I am trying to strip out. I did just try it with removing the -ExpandProperty switch and only using the select statement, but that doesn't seem to work at all, it only includes the bogus text that way, no properties are loaded.

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Implicit remoting returned in text

Post by jvierra » Tue Oct 29, 2019 11:56 am

The results returned are in a table.

$table = Receive-Job <jobname> | Select-Object Description,Name,Managers,Members

Without your code there is no way to understand what you are trying to do.

Start by creating a simple form that does only that one thing. Note that all jobs add properties to the results. You must select the properties that you want.

Also be aware the "members" and "managers" are arrays.

User avatar
PS_Ross
Posts: 58
Joined: Thu Mar 01, 2018 7:46 am

Re: Implicit remoting returned in text

Post by PS_Ross » Tue Oct 29, 2019 12:50 pm

Thanks for that response. However, I did post my code above, and I do select the properties that I want. This is what I am using to select the properties. I am also aware of the array's that are returned, thanks for the reminder though.

I tried to keep it short so I didn't have to post a ton of code that you have to sort through, but here is the entire code block for the background job..

Code: Select all

#region Load chat room
$RoomData = @{
	Name	  = 'RoomData'
	JobScript = {
			
		Param ($global:UserCred,
			$global:RoomName
		)
			
		try
		{				
			$session = New-PSSession -ConnectionUri "https://sfbpool.domain.com/ocsPowerShell" -Credential $global:UserCred
			Import-PSSession $session -AllowClobber
				
			$Table = [PSCustomObject]([Ordered]@{
					'Description' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Description
					'Name' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Name
					'Managers' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Managers
					'Members' = Get-CsPersistentChatRoom -Identity $global:RoomName | select -ExpandProperty Members
				})
		}
		catch
		{
			$Table = [PSCustomObject]([Ordered]@{
					'Check'	       = "Fail"
					'ErrorMessage' = $PSItem
				})
		}
			
		$Table
			
		for ($i = 0; $i -lt 50; $i++) { Start-Sleep -Milliseconds 100 }
	}
	ArgumentList = $global:UserCred, $global:RoomName
	CompletedScript = {
		Param ($Job)
		$results = Receive-Job -Job $Job | select Description, Name, Managers, Members
		
		$global:RoomData = $results
	}
	UpdateScript = {
		Param ($Job)
	}
}
#endregion Load chat room
	
Add-JobTracker @RoomData
In the next form, when the description is loaded into a textbox, I call it like so..

$textbox1.Text = $global:RoomData.Description

DISCLAIMER: The entire code block above works as expected 100% of the time. I do understand you may do it differently in some areas. This post is not to assist with the method of the code, but only trying to remove the bogus text that comes back with it as I originally stated in my first post, see screenshot for reference also included in first post.

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Implicit remoting returned in text

Post by jvierra » Tue Oct 29, 2019 2:38 pm

PS_Ross wrote:
Tue Oct 29, 2019 12:50 pm
$textbox1.Text = $global:RoomData.Description

DISCLAIMER: The entire code block above works as expected 100% of the time. I do understand you may do it differently in some areas. This post is not to assist with the method of the code, but only trying to remove the bogus text that comes back with it as I originally stated in my first post, see screenshot for reference also included in first post.
Your approach to the code can cause much of your issue so I want to make it legitimate code that does not have many unnecessary moving parts and so that it behaves normally in a job and in a form.
Most of your coding is actually wrong or causes issues that you don't see right now.

Also, in order to understand code it is necessary for me to place it in a standard for,. This is what I have learned and found most useful after 40+ years of programming and 10+ years of writing PowerShell scripting. It is not intended to be critical - just technically correct.

Locked