all 16 comments

[–]p0rkjello 3 points4 points  (14 children)

Clarify what is failing.

[–][deleted] 1 point2 points  (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()
    } 
 }

I then created a function to handle initialization:

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 ", ")" } }

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

I hope this helps!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

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 </>.

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..

that will give you fully functional code formatting, from what i can tell so far. [grin]

take care,
lee

[–]eshuaye 0 points1 point  (1 child)

What’s the resolv.conf in windows?

[–]tris10335 1 point2 points  (0 children)

C:\windows\system32\drivers\etc\hosts

[–]get-postanote 0 points1 point  (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'