/
IP-Assets.ps1
39 lines (35 loc) · 1.39 KB
/
IP-Assets.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
clear
$results=@()
$Subnet = Read-Host -Prompt "Please Enter the Subnet the you want to search in (Example: 192.168.0)"
$IPStart = Read-Host -Prompt "Please Enter the First IP in that range (Example:1)"
$IPEnd = Read-Host -Prompt "Please Enter the Last IP in that range (Example:255)"
$Report = "$Subnet-report.csv"
if (Test-Path "$Report") {
$results += Import-Csv -Path "$Report"
foreach ($element in $results) {
If (Test-Connection -count 1 -comp $element.ComputerName -quiet) {
echo $element.ComputerName "is still online"
$element.Online = "Still online"
} else {
$element.Online = "No"
}
}
} else {
$IPStart..$IPEnd | %{
$IP = "$Subnet.$_"
If (Test-Connection -count 1 -comp $IP -quiet) {
$HostName = [System.Net.Dns]::GetHostByAddress($IP).HostName
$HostName = $HostName.trimend(".domain")
echo "$IP - $Hostname"
$details = @{
Date = get-date
ComputerName = $Hostname
IPAddress = $IP
Online = "Yes"
}
$results += New-Object PSObject -Property $details
}
}
}
$results | export-csv -Path "$Report" -NoTypeInformation
Invoke-Item "$Report"