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 (60 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

Hi all, I've created a 'View User' command via the Web Interface Configurator. I don't want users to be able to make any changes, so I've created a Custom ... there any way to remove this, short of removing the entire Exchange section itself? Thanks, David

asked Sep 5 by dshortall (80 points)
0 votes
1 answer

How I can ignore a part of the lastname in username composition? Example: In the fullname "John da Silva", "da Silva", is the lastname, so, I need ignore the "da " in the composition of username, when I create the new user.

asked May 22 by fgmello (40 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)
3,588 questions
3,277 answers
8,303 comments
548,100 users