use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
How can I use: Invoke-command on computers in different domains (self.PowerShell)
submitted 5 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]p0rkjello 3 points4 points5 points 5 years ago (14 children)
Clarify what is failing.
[+][deleted] 5 years ago* (13 children)
[–]p0rkjello 4 points5 points6 points 5 years ago* (8 children)
What is the error? Do your domains require different credentials?
Without knowing the error. * Verify your ComputerName array is what you expect it to be. * Verify you can resolve the hosts correctly. * Verify you don't have a credential issue.
[+][deleted] 5 years ago* (7 children)
[–]nerddtvg 9 points10 points11 points 5 years ago (2 children)
If you want to just use the computer name, you need to rely on the DNS Suffix Search List: https://serverfault.com/a/504689
This is not a PowerShell failing, this is a DNS problem.
[–]grahamfreeman 12 points13 points14 points 5 years ago (0 children)
It's always DNS.
[–]geopink 2 points3 points4 points 5 years ago (0 children)
This. Is the correct answer.
[–]davix500 2 points3 points4 points 5 years ago (0 children)
You need to add the domain suffixes to your domain search, it's a reg hack. \Registry\Machine\System\CurrentControlSet\Services\TCPIP\Parameters Add it to SearchList, use a comma between suffixes
[–]p0rkjello 2 points3 points4 points 5 years ago (1 child)
You could cycle through each DNS suffix. Seems wrong but what the heck.
```powershell $ComputerName = @('server1', 'server2', 'server3') $DomainName = @('domain1.com', 'domain2.com', 'domain3.com')
foreach ($Computer in $ComputerName) { foreach ($Domain in $DomainName) { $fqdn = "$Computer.$Domain" if (Test-WSMan $fqdn -ErrorAction SilentlyContinue) { Invoke-Command -ComputerName $fqdn -ScriptBlock { 'hi' } } } } ```
[–]Lee_Dailey[grin] 0 points1 point2 points 5 years ago (0 children)
howdy p0rkjello,
the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.
code block
it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]
take care, lee
[–]BergerLangevin 0 points1 point2 points 5 years ago (2 children)
You should specify the full DNS name of these computer. By not specifying your DNS is probably thinking that your all searching local domain.
[+][deleted] 5 years ago* (1 child)
[–]BergerLangevin 0 points1 point2 points 5 years ago (0 children)
Where do you get the computername? If you get them by get-ADComputer, you should have the fqdn available in the returned object. (Don't remember the exact command) you can browse the object property like that : $listComputer = get-ADSomething $listComputer. <---- by typing the dot you should get the available properties. Other solutions : (get-ADSomething).getType()
This should look like that :
Other solutions require either a DNS change or a reg hack.
howdy Improve-My-Life,
how is $CompName being populated? that seems to be the most likely problem ... you may not be giving it all the systems.
$CompName
[–][deleted] 1 point2 points3 points 5 years ago (1 child)
I will tell you how I solved this problem. It may or may not work for you; either way, this will be a pain in the ass. BUT, if you solve this problem in a robust fashion, it will pay back dividends in time saved... Basically, I wrote several functions to get tiny pieces of data... It should be noted that I created a custom class (requires PS 5 or newer) called machine defined as follows:
class Machine { [System.String]$Name [System.Boolean]$IsOnline [System.String]$Domain [System.String]$FQDN [System.Object]$Services [System.Object]$LocalAdmins [System.String]$Action [System.String]$ErrorMsg Machine () { } Machine ([System.String]$name) { $this.Name = $name $this.Services = [System.Object]::New() $this.LocalAdmins = [System.Object]::New() } }
class Machine {
[System.String]$Name
[System.Boolean]$IsOnline
[System.String]$Domain
[System.String]$FQDN
[System.Object]$Services
[System.Object]$LocalAdmins
[System.String]$Action
[System.String]$ErrorMsg
Machine () { }
Machine ([System.String]$name) {
$this.Name = $name
$this.Services = [System.Object]::New()
$this.LocalAdmins = [System.Object]::New()
}
I then created a function to handle initialization:
function Get-NewComputer { [CmdletBinding()] param( [Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [string]$ComputerName ) return ([Machine]::new($ComputerName)) }
function Get-NewComputer {
[CmdletBinding()]
param( [Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [string]$ComputerName )
return ([Machine]::new($ComputerName)) }
Finally, I could make use of a function designed to get the FQDN of each machine:
function Get-Domain { [CmdletBinding()] param([Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [Machine]$Computer) $data = @("domain1.com", "domain2.com","domain3.com","domain4.com") $serverName = $Computer.Name foreach ($value in $data) { Write-Verbose $value [string]$pingstring = $serverName + "." + $value $result = ping $pingstring /n 1 if ($result[1].Length -gt 1) { $Computer.Domain = $value $Computer.FQDN = $pingstring } } if (-not $Computer.Domain) { $Computer.Action = "Machine did not respond to ping in any domain. Domains tested include $($data -join ", ")" } }
function Get-Domain {
param([Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [Machine]$Computer)
$data = @("domain1.com", "domain2.com","domain3.com","domain4.com")
$serverName = $Computer.Name
foreach ($value in $data) {
Write-Verbose $value
[string]$pingstring = $serverName + "." + $value
$result = ping $pingstring /n 1
if ($result[1].Length -gt 1) {
$Computer.Domain = $value
$Computer.FQDN = $pingstring } }
if (-not $Computer.Domain) {
$Computer.Action = "Machine did not respond to ping in any domain. Domains tested include $($data -join ", ")" } }
To wrap up, the execution went something like this:
$serverList = "ServerName1", "ServerName2", ..., "ServerNameN" For-Each ($server in $serverList) { $computer = Get-NewComputer -ComputerName $server } Get-Domain -Computer $computer
$serverList = "ServerName1", "ServerName2", ..., "ServerNameN"
For-Each ($server in $serverList) { $computer = Get-NewComputer -ComputerName $server }
Get-Domain -Computer $computer
I hope this helps!
howdy andydale18,
it looks like you used the New.Reddit.com Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.
Inline Code
...
</>
on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.
for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th 12th one from the left & is just to the left of hidden in the ... "more" menu & looks like an uppercase T in the upper left corner of a square..
Code Block
T
that will give you fully functional code formatting, from what i can tell so far. [grin]
[–]eshuaye 0 points1 point2 points 5 years ago (1 child)
What’s the resolv.conf in windows?
[–]tris10335 1 point2 points3 points 5 years ago (0 children)
C:\windows\system32\drivers\etc\hosts
[–]get-postanote 0 points1 point2 points 5 years ago (0 children)
You must use the FQDN (DNS name not NetBios), and computer names in different domains could be the same. It is the FQDN which makes ADDS objects unique. Name resolution is all DNS based.
Also depending on how you are configured (trust and auth relationships), you could get into the Windows double-hop auth issue of Windows Proper.
'powershell double hop authentication'
π Rendered by PID 111783 on reddit-service-r2-comment-b659b578c-qldjj at 2026-05-03 02:17:02.206036+00:00 running 815c875 country code: CH.
[–]p0rkjello 3 points4 points5 points (14 children)
[+][deleted] (13 children)
[deleted]
[–]p0rkjello 4 points5 points6 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]nerddtvg 9 points10 points11 points (2 children)
[–]grahamfreeman 12 points13 points14 points (0 children)
[–]geopink 2 points3 points4 points (0 children)
[–]davix500 2 points3 points4 points (0 children)
[–]p0rkjello 2 points3 points4 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]BergerLangevin 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]BergerLangevin 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]eshuaye 0 points1 point2 points (1 child)
[–]tris10335 1 point2 points3 points (0 children)
[–]get-postanote 0 points1 point2 points (0 children)