Powershell: scan for computername prefix xyz

Hi,

Is there a way to use https://www.powershelladmin.com/wiki/Port_scan_subnets_with_PSnmap_for_PowerShell#Screenshot_examples_of_PSnmap
psnmap for powershell and scan to computername prefixxyz so it would scan
prefixxyz01
prefixxyz02
prefixxyz03

etc?

Please advise.
J.
janhoedtAsked:
Who is Participating?
 
David Johnson, CD, MVPConnect With a Mentor OwnerCommented:
no it needs an array of computernames
you may want to use
$computers = get-adcomputer -filter * | where-object  {$_.Name -like "PC*"}| select-object -expandproperty Name
psnmap -computer $computers

Open in new window

0
 
footechCommented:
A limitation of just a prefix "prefixxyz" is really too broad, and I'm quite certain that the script can't handle it.
But if your list of machines is just a number after the prefix (like in your examples "prefixxyz01","prefixxyz02", etc.), then you could easily generate this list of machines beforehand and supply that list to the script's -computername parameter.
For example:
$comps = 0..99 | % { "{0:00}" -f $_ }
.\psnmap.ps1 -computername $comps

Open in new window

0
 
footechCommented:
David's solution is the way to go when you have a source (like ActiveDirectory) that will have all your potential hosts.  If you were in a peer-to-peer situation, or scanning hosts which you couldn't pull their names from a masterlist, then I think mine is the way to go.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.