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

5 Answers 5

31

Soemtimes the old school way is the easiest.

net view
Sign up to request clarification or add additional context in comments.

1 Comment

And to parse check this one-liner from poshcode.org/882 switch -regex (NET.EXE VIEW) { "^\\\\(?<Name>\S+)\s+" {$matches.Name}}
7

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

([adsi]"WinNT://WORKGROUP").Children

Comments

7

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.

Comments

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

2 Comments

How would I format the output of this to list or csv?
@bitshift Just tack this onto the end: "| %{ $_.Path }"
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.