20

I want to write a PS script, that would go through all machines it can find on a local network, take a look at "SomeDirectory" and if a file there exists, overwrite it with a new version for a UNC path..

The First problem is getting a list of PC's that you can find in Windows -> Network enter image description here

Marty
  • 3,485
  • 8
  • 38
  • 69

5 Answers5

31

Soemtimes the old school way is the easiest.

net view
mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • 1
    And to parse check this one-liner from http://poshcode.org/882 `switch -regex (NET.EXE VIEW) { "^\\\\(?\S+)\s+" {$matches.Name}}` – Guillaume Gros Jan 30 '15 at 14:07
7

And to piggy-back even further on FoxDeploy's answer:

(([adsi]"WinNT://$((Get-WMIObject Win32_ComputerSystem).Domain)").Children).Where({$_.schemaclassname -eq 'computer'})

This will grab just the computers on the domain, not all AD objects (such as users, organizational groups, etc.).

Kevin McDowell
  • 532
  • 6
  • 20
6

Here's another thing you can do (depending on your worgroup name).

([adsi]"WinNT://WORKGROUP").Children
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
6

Piggy-backing on Shay's answer:

([adsi]"WinNT://$((Get-WMIObject Win32_ComputerSystem).Domain)").Children

This will grab your domain or workgroup name and use that for you.

FoxDeploy
  • 12,569
  • 2
  • 33
  • 48
0

ADSI does not work out of domain. If you have only workgroup you need to use NETBIOS for list of registered machines. Output of the "nbtstat" is only string, not object. Manipulation is not so easy but you receive number of registered machines and network names.

nbtstat -r