Running command on multiple non-domain remote computer

I have created few pssession using new-pssession.

I can see them using get-pssession.

Is there a trick to pipe get-pssession | invoke-command -session?

If I create the session using variable, $session1, $session2, $session3 I can use invoke-command -session $session1,$session2,$session3 but the previous pipe dont work as I expect.

The goal is to take a list from my internal ticketing server, and run the same command against 50+ server.
All of those server are enabled for remoting using SSL and they are all working individually.

hope it clear
Thank in advance.

Doesn’t look like you can pipe get-session to invoke-command, however this might be helpful

Example 9: Run a background job in a set of sessions

PS C:> $s = New-PSSession -ComputerName (Get-Content Servers.txt) -Credential Domain01\Admin01 -ThrottleLimit 16
PS C:> Invoke-Command -Session $s -ScriptBlock {Get-Process PowerShell} -AsJob

You cannot use local variables in remote sessions without setting the scope.


Windows PowerShell assumes that the variables used in remote commands are
defined in the session in which the command runs.

In the following example, the $ps variable is defined in the temporary session
in which the Get-WinEvent command runs.

Invoke-Command -ComputerName S1 -ScriptBlock {$ps = “Windows PowerShell”; Get-WinEvent -LogName $ps}

Similarly, when the command runs in a persistent session (PSSession), the
remote variable must be defined in the same PSSession.


You can also use local variables in remote commands, but you must indicate that
the variable is defined in the local session.

Beginning in Windows PowerShell 3.0, you can use the Using scope modifier to
identify a local variable in a remote command.

The syntax of Using is as follows:

The syntax is: $Using:

In the following example, the $ps variable is created in the local session, but
is used in the session in which the command runs. The Using scope modifier
identifies $ps as a local variable.

about Remote Variables - PowerShell | Microsoft Learn

You cannot use all of PSRemoting (Invoke) unless you are an admin on the remote host.

So, you say these are workgroup systems. So, you set all the PSRemoting workgroup settings?

PowerShell remoting between two workgroup machines
PowerShell remoting between two workgroup machines | Microsoft Learn

Actually, I am an MSP, I take care of 250 different SMB.

Some of them as only few computer and a DC, some get exchange. Most of them are using Hyper-V host.

Here is another question related to this. Let take a customer with 2 server. Both set-up using SSL. So I had to put a hostname. Ex Because I want them both to be available I set-up the first one on port 45986 and second one on port 45987.

If I use invoke-command on those 2 computers at the same time, the result come back and a new column pscomputername is added. In both case, it Internal machine name are different, DC and Hv1. Can we work around this?