PowerShell Network Scanning

PowerShell is one of the most important tools for a system administrator. Here are some scripts to scan and get information from your network with powershell.

Jan 9, 2023 - 15:44
Feb 20, 2023 - 13:58
PowerShell Network Scanning
PowerShell Network Discovery

Quick Link to PowerShell Script:

powershell/remove_browsers.ps1 at main · kbsuperuser/powershell (github.com)

Scan the network to find devices with PowerShell

-------

# Set the network range to scan
$network = "192.168.1.1/24"

# Scan the network and retrieve a list of active devices
$devices = Get-WmiObject -Class Win32_PingStatus -Filter "Address='$network' AND StatusCode=0" | Select-Object -ExpandProperty Address

# Print the list of active devices
foreach($device in $devices) {
    Write-Output $device
}

---------

 The sciprt uses the Get-WmiObject cmdlet to perform a ping scan on the specified network range. You may need to modify the network range and any other settings to suit your needs.

Export to previoues results to a csv file

-------

# Set the network range to scan
$network = "192.168.1.1/24"

# Scan the network and retrieve a list of active devices
$devices = Get-WmiObject -Class Win32_PingStatus -Filter "Address='$network' AND StatusCode=0" | Select-Object -ExpandProperty Address

# Export the list of active devices to a CSV file
$devices | Export-Csv -Path "C:\temp\devices.csv" -NoTypeInformation

-------

Add Some More Information and export the results as a csv file

------

<#
.SYNOPSIS
Scan Network and Export The Results
.DESCRIPTION
This PowerShell script scan the networks and export the results to a csv file. Update the network range and destination of the CSV file.
.EXAMPLE
PS> ./network_scan
.LINK
https://github.com/kbsuperuser/powershell
.NOTES
Author: kbsuperuser.com | License: CC0
#>
# Set the network range to scan
$network = "192.168.1.1/24"
# Scan the network and retrieve a list of active devices
$devices = Get-WmiObject -Class Win32_PingStatus -Filter "Address='$network' AND StatusCode=0" | Select-Object -ExpandProperty Address
# Retrieve additional information for each active device
$devices = foreach($device in $devices) {
$info = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPAddress='$device'"
[pscustomobject]@{
"IPAddress" = $device
"Hostname" = $info.DNSHostName
"Manufacturer" = $info.Manufacturer
}
}
# Export the list of active devices to a CSV file
$devices | Export-Csv -Path "C:\temp\devices.csv" -NoTypeInformation

----------

  • You may add some more details needed such as last logon user, build number etc. Note that this script will only work on networks that you have permission to access and scan. !

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow