0 votes

hello,

I have somethings like this :

#Start the process on the remote machine
$Context.LogMessage("Get statistivcs on %cn%", "Information")
$Server = New-PSSession -ComputerName $computername -Credential $credential

Invoke-Command -Session $Server -ScriptBlock {$a = Get-RemoteAccessConnectionStatisticsSummary

}
$Context.LogMessage("$a", "Information")

remove-PSSession $Server

I need to pass the value of $a into the main script so I can see $a in $Context.LogMessage.

is that possible?

Thanks.

by (1.1k points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

To get output from the Invoke-Command cmdlet, you need to add the return statement to the block invoked on the remote machine:

# Start the process on the remote machine
$Context.LogMessage("Get statistics on %cn%", "Information")

$session = New-PSSession -ComputerName $computername -Credential $credential

$summary = Invoke-Command -Session $session -ScriptBlock {$a = Get-RemoteAccessConnectionStatisticsSummary
return $a
}

$Context.LogMessage("$summary", "Information")

Remove-PSSession $session
0

it works, thanks.

Related questions

0 votes
1 answer

Using the powershell module, I know how to create a scheduled task, and also how to bind to a scheduled task that is already known. I also have used code to try creating ... same time as another. These are all one-time tasks and will be removed once executed.

asked Jan 19 by aweight (40 points)
0 votes
1 answer

Using this built in function: There is no option to change the domain on the user account, however this is not the domain we use for UPN. However after creating a user, you can change it but trying to avoid going back into the object.

asked Apr 14, 2023 by mightycabal (1.0k points)
0 votes
1 answer

Currently, when I disable a user account in Adaxes, the group memberships of the user remain intact. I'd like to automate the removal of group memberships such as distribution ... a list of groups/DL that the user was previously in and removed from. Thanks!

asked Nov 3, 2021 by jayden.ang (20 points)
0 votes
1 answer

for example i add a form "create user for France" in the left pane, how can i translate it automatically when the UI in in French ? thank you

asked Apr 29, 2021 by GG (70 points)
0 votes
1 answer

Occationally Service Desk staff need to clear a DNS record when a desktop has been reimaged but is keeping the same name as loses the ability to manage its original DNS ... running in ADAXES. Can I just install the applet on the ADAXES server using powershell?

asked Jan 17, 2023 by stevehalvorson (110 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users