Implicit remoting returned in text

Ask your 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.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Implicit remoting returned in text

Post by jvierra »

Replace this code and look at the message output. Post the contents of the file that is created.

Code: Select all

		CompletedScript = {
			Param ($Job)
            
			$results = Receive-Job -Job $Job
            
            $msg = $results | gm | Out-String
            $msg | Out-File c:\results.log
            [System.Windows.Forms.MessageBox]::Show($msg)
                
            if ($results.Check -eq "Fail")
			{
				[System.Windows.Forms.MessageBox]::Show("Failed to load room data, please try again.", 'Room data')
				return
			}
			
			$RoomData = $results
			$textbox2.Text = $RoomData.Description
		}
[code]
User avatar
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Re: Implicit remoting returned in text

Post by Shelltastic »

Here is the file it generated..

Code: Select all




   TypeName: Deserialized.System.Management.Automation.PSModuleInfo

Name                        MemberType   Definition                                                                                                            
----                        ----------   ----------                                                                                                            
GetType                     Method       type GetType()                                                                                                        
ToString                    Method       string ToString(), string ToString(string format, System.IFormatProvider formatProvider), string IFormattable.ToStr...
PSComputerName              NoteProperty System.String PSComputerName=localhost                                                                                
PSShowComputerName          NoteProperty System.Boolean PSShowComputerName=False                                                                               
RunspaceId                  NoteProperty System.Guid RunspaceId=6733bb1b-309b-4e60-87f7-7d468d6f3c25                                                           
AccessMode                  Property     System.String {get;set;}                                                                                              
Author                      Property      {get;set;}                                                                                                           
ClrVersion                  Property      {get;set;}                                                                                                           
CompanyName                 Property      {get;set;}                                                                                                           
Copyright                   Property      {get;set;}                                                                                                           
Definition                  Property     System.String {get;set;}                                                                                              
Description                 Property     System.String {get;set;}                                                                                              
DotNetFrameworkVersion      Property      {get;set;}                                                                                                           
ExportedAliases             Property     Deserialized.System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Pu...
ExportedCmdlets             Property     Deserialized.System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Pu...
ExportedCommands            Property     Deserialized.System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Pu...
ExportedFormatFiles         Property     Deserialized.System.Collections.ObjectModel.ReadOnlyCollection`1[[System.String, mscorlib, Version=4.0.0.0, Culture...
ExportedFunctions           Property     Deserialized.System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Pu...
ExportedTypeFiles           Property     Deserialized.System.Collections.ObjectModel.ReadOnlyCollection`1[[System.String, mscorlib, Version=4.0.0.0, Culture...
ExportedVariables           Property     Deserialized.System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Pu...
ExportedWorkflows           Property     Deserialized.System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Pu...
FileList                    Property     Deserialized.System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKe...
Guid                        Property     System.Guid {get;set;}                                                                                                
HelpInfoUri                 Property      {get;set;}                                                                                                           
LogPipelineExecutionDetails Property     System.Boolean {get;set;}                                                                                             
ModuleBase                  Property     System.String {get;set;}                                                                                              
ModuleList                  Property     Deserialized.System.Collections.ObjectModel.Collection`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral...
ModuleType                  Property     System.String {get;set;}                                                                                              
Name                        Property     System.String {get;set;}                                                                                              
NestedModules               Property     Deserialized.System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.PSModuleInfo, System...
OnRemove                    Property     System.String {get;set;}                                                                                              
Path                        Property     System.String {get;set;}                                                                                              
PowerShellHostName          Property      {get;set;}                                                                                                           
PowerShellHostVersion       Property      {get;set;}                                                                                                           
PowerShellVersion           Property      {get;set;}                                                                                                           
Prefix                      Property     System.String {get;set;}                                                                                              
PrivateData                 Property     Deserialized.System.Collections.Hashtable {get;set;}                                                                  
ProcessorArchitecture       Property     System.String {get;set;}                                                                                              
RequiredAssemblies          Property     Deserialized.System.Collections.ObjectModel.Collection`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral...
RequiredModules             Property     Deserialized.System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Management.Automation.PSModuleInfo, System...
RootModule                  Property     System.String {get;set;}                                                                                              
Scripts                     Property     Deserialized.System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKe...
SessionState                Property     System.String {get;set;}                                                                                              
Version                     Property     System.Version {get;set;}                                                                                             


   TypeName: Deserialized.System.Management.Automation.PSCustomObject

Name               MemberType   Definition                                                                                                                     
----               ----------   ----------                                                                                                                     
Equals             Method       bool Equals(System.Object obj)                                                                                                 
GetHashCode        Method       int GetHashCode()                                                                                                              
GetType            Method       type GetType()                                                                                                                 
ToString           Method       string ToString()                                                                                                              
Description        NoteProperty System.String Description=Msg Mobility support chat                                                    /SINCE 2005...          
Managers           NoteProperty Deserialized.System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7...
Members            NoteProperty Deserialized.System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7...
Name               NoteProperty System.String Name=MSGMobility_Support                                                                                         
PSComputerName     NoteProperty System.String PSComputerName=localhost                                                                                         
PSShowComputerName NoteProperty System.Boolean PSShowComputerName=False                                                                                        
RunspaceId         NoteProperty System.Guid RunspaceId=6733bb1b-309b-4e60-87f7-7d468d6f3c25                                                                    





jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Implicit remoting returned in text

Post by jvierra »

So it is clear your job is failing and returning junk which can be due to many issues. There are many issues with the online modules so be sure you have the latest module installed. I have looked at your code more critically and find many deficiencies in the design of the code for use in a job. There are too many paths that can thwwo exceptions and you are not accounting for those exceptions. I have modified the job code to handle all of the exception ases that I believe can happen. If this doesn't dicover the cause then we will have to look into deeper methods of debugging this.

Run the attached., I cannot run it on my end because I have no rooms set up on the test server
Attachments
Example_fix1.psf
(23.52 KiB) Downloaded 108 times
User avatar
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Re: Implicit remoting returned in text

Post by Shelltastic »

I will give it a run now and post back, FYI though this is not an online module, this is an on-prem environment. I am not sure what you are seeing that makes you think it's failing, because I do get the correct results that I am looking for when I execute my code, even in the stripped down example, I still get the results I want with 0 failures... Again, it's just that one line being added into the return data that I would like to remove.
User avatar
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Re: Implicit remoting returned in text

Post by Shelltastic »

Just ran your updated code, looks like same thing. It works correctly just like my original code does, however it still contains that default return data. Screen shot attached to this message using your revised code.
Attachments
Capture.PNG
Capture.PNG (23.59 KiB) Viewed 4328 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Implicit remoting returned in text

Post by jvierra »

And if you run that exact code at a prompt you get different results.

Run the following and inspect the variables.

Code: Select all

$JobScript = {
	Param (
        $UserCred,
		$RoomName
	)
	
	try{
             $ErrorActionPreference = 'Stop'
	     $session = New-PSSession -ConnectionUri 'https://sfbpoolw2.cigna.com/ocsPowerShell' -Credential $UserCred
	     Import-PSSession $session -AllowClobber
		
            # pre-allocate the object for consistent results.
            $table = [PSCustomObject][Ordered]@{
                 Description   = $null
                 Name	      = $null  
                 Managers      = $null
                 Members	      = $null
                Check	      = 'Success'
                ErrorMessage  = $null
            }
            
	    $room = Get-CSPersistentChatRoom -Identity $RoomName
	    $table.Description = $Room.Description
	    $table.Name	       = $Room.Name
	    $table.Managers    = $Room.Managers
	    $table.Members	   = $Room.Members
            $table.Check	   = 'Success'

    }
    catch{
        $table.Check= 'Fail'
        $table.ErrorMessage = "$_"
    }
    $table
}

$job = Start-Job -Name RoomData -ScriptBlock $JobScript -ArgumentList $userCred, '<roomname>' 
$results | Receive-Job -Wait
$results.Error
$results.Description

# check the following carefully
$results.ChildJobs[0].Error
$results | gm
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Implicit remoting returned in text

Post by jvierra »

From the issue the cause may be one of the issues that have been reported about many modules for Exchange and other newer modules both online and on-prem. If the above works then change the mode of the PSF to MTA if STA or STA if MTA.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Implicit remoting returned in text

Post by jvierra »

I just though of another issue that can caus this behavior and I will post it after your test results. It is a behavior that can occur because the return object from some commands can get wrapped oddly when run in a form.
User avatar
Shelltastic
Posts: 65
Last visit: Mon Feb 19, 2024 11:31 am

Re: Implicit remoting returned in text

Post by Shelltastic »

Just ran it in both modes, looks like I am getting the same result, still adding in the extra line of text.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Implicit remoting returned in text

Post by jvierra »

PS_Ross wrote: Thu Oct 31, 2019 7:07 am Just ran it in both modes, looks like I am getting the same result, still adding in the extra line of text.
It appears that the module is incompatible with Forms. This is rue of a number of newer modules for Exchange and other subsystems like SharePoint.

I would also run the following to check the exact type of the returned objects to see if they are getting converted somehow.

Code: Select all

$job = Start-Job -Name RoomData -ScriptBlock $JobScript -ArgumentList $userCred, '<roomname>' 
$results | Receive-Job -Wait
$results.GetType()
$results.Error
$results.Description
$results.Description.GetType()

# check the following carefully
$results.ChildJobs[0].Error
$results | gm
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked