-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck_DP_Connection.ps1
More file actions
37 lines (29 loc) · 1.88 KB
/
Check_DP_Connection.ps1
File metadata and controls
37 lines (29 loc) · 1.88 KB
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
<#
ScriptFunction: Gather information regarding a particular computer object's network settings
Author: Josh Kennedy
Date: 2020/01/20
#>
$DPs = Get-Content "C:\TEMP\DPs.txt"
$DPStatus = New-Object -TypeName psobject
foreach ($DP in $DPs){
if (Test-Connection -ComputerName $DP -Count 1 -ErrorAction SilentlyContinue){
$Gateway = gwmi -computername $DP win32_networkadapterconfiguration -ErrorAction SilentlyContinue | ?{$_.ipenabled} | select defaultipgateway
$Gateway = $Gateway.defaultipgateway | Out-String
$Ping = Test-Connection -ComputerName $DP -Count 1 -ErrorAction SilentlyContinue
$DPStatus | Add-Member -MemberType NoteProperty -Name Pingable -Value "Yes" -Force
$DPStatus | Add-Member -MemberType NoteProperty -Name HostName -Value $DP -Force
$DPStatus | Add-Member -MemberType NoteProperty -Name IPAddress -Value $Ping.IPV4Address -Force
$DPStatus | Add-Member -MemberType NoteProperty -Name Gateway -Value $Gateway -Force
$DPStatus | Export-Csv -NoTypeInformation -Append -Path "C:\temp\DPStatus.csv"
}
else {
$Gateway = gwmi -computername $DP win32_networkadapterconfiguration -ErrorAction SilentlyContinue | ?{$_.ipenabled} | select defaultipgateway
$Gateway = $Gateway.defaultipgateway | Out-String
$Ping = Test-Connection -ComputerName $DP -Count 1 -ErrorAction SilentlyContinue
$DPStatus | Add-Member -MemberType NoteProperty -Name Pingable -Value "No" -Force
$DPStatus | Add-Member -MemberType NoteProperty -Name HostName -Value $DP -Force
$DPStatus | Add-Member -MemberType NoteProperty -Name IPAddress -Value "Null" -Force
$DPStatus | Add-Member -MemberType NoteProperty -Name Gateway -Value "Null" -Force
$DPStatus | Export-Csv -NoTypeInformation -Append -Path "C:\temp\DPStatus.csv"
}
}