0 votes


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?


by (1.1k points)

1 Answer

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


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

it works, thanks.

Related questions

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

I have an ADP Sync scheduled task that modifies and creates users from a csv file. I also have reports that show new users created and management history for user ... ADP Sync scheduled task so that they only run after the ADP Sync task is complete?

asked Jan 7, 2020 by barberk (60 points)
0 votes
1 answer

I would like to add a parameter for country to a custom command. Since the country has to be entered correctly in order for Active Directory to accept it, I would like to ... ? I didn't find it in the documentation and the sample scripts didn't use parameters.

asked Jun 4, 2020 by mark.it.admin (1.8k points)
0 votes
1 answer

Is there a way to get the name of the user who approved a request and supply that to a step inside of a custom command? For example, HR submits a status change for an employee. ... and pass it as a param in a custom command that is called in one of the steps?

asked May 12, 2021 by davfount90 (20 points)
2,740 questions
2,474 answers
1,372,186 users