Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell get a list of network machines

Tags:

powershell

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

like image 774
Marty Avatar asked Apr 03 '13 20:04

Marty


People also ask

How do I get a list of computers in PowerShell?

There is no specific PowerShell cmdlet or script to fetch all computers accounts in a specific Active Directory (AD) domain. You will have to use the Get-ADComputer cmdlet, and use the right parameters and filters to get the desired list of AD computer accounts.

How do I list all computers in Active Directory?

We can get a list of all computers in Active Directory using the Powershell cmdlet Get-ADComputer. The Get-ADComputer cmdlet supports SQL like filter and LDAP filter to filter AD computers.

How do I get hardware information in PowerShell?

Enter the PowerShell system info commandType Get-ComputerInfo and press “Enter”. It will return all of your system specifications, from the Windows version to Bios data.

Which command is used to get all physical network adapters in PowerShell?

The Get-NetAdapter cmdlet gets the basic network adapter properties. By default only visible adapters are returned. To see the common network adapter properties, pipe the output into the Format-List cmdlet.


3 Answers

Soemtimes the old school way is the easiest.

net view
like image 76
mjolinor Avatar answered Oct 02 '22 14:10

mjolinor


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

like image 30
Kevin McDowell Avatar answered Oct 02 '22 15:10

Kevin McDowell


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

([adsi]"WinNT://WORKGROUP").Children
like image 6
Shay Levy Avatar answered Oct 02 '22 14:10

Shay Levy