# Running command on multiple non-domain remote computer

**URL:** <https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137>\
**Category:** PowerShell Help\
**Created:** [February 15, 2018, 3:53pm UTC](https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137 "2018-02-15T15:53:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cartierinfo](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@cartierinfo](https://forums.powershell.org/u/cartierinfo)\
**Post date:** [February 15, 2018, 3:53pm UTC](https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137/1 "2018-02-15T15:53:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [February 15, 2018, 4:10pm UTC](https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137/2 "2018-02-15T16:10:58Z")

</div>

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

[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssession?view=powershell-5.1](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssession?view=powershell-5.1)

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

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

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [February 15, 2018, 9:16pm UTC](https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137/3 "2018-02-15T21:16:09Z")

</div>

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

> USING REMOTE VARIABLES
> 
> 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.
> 
> USING LOCAL VARIABLES
> 
> 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](http://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_variables?view=powershell-5.1)’

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](http://blogs.msdn.microsoft.com/wmi/2009/07/24/powershell-remoting-between-two-workgroup-machines)’

---

<div class="post-metadata">

**Author:** ![cartierinfo](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@cartierinfo](https://forums.powershell.org/u/cartierinfo)\
**Post date:** [February 16, 2018, 7:43am UTC](https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137/4 "2018-02-16T07:43:26Z")

</div>

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 [remote.contoso.com](http://remote.contoso.com) 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 [remote.contoso.com](http://remote.contoso.com). Internal machine name are different, DC and Hv1. Can we work around this?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/running-command-on-multiple-non-domain-remote-computer/10137/5 "2024-05-16T20:36:22Z")

</div>


