-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetIP.ps1
46 lines (43 loc) · 1.28 KB
/
GetIP.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
40
41
42
43
44
45
46
<#
.SYNOPSIS
Gets and displays the IP address of a computer
.DESCRIPTION
This script uses Win32_NetworkAdapterConfiguration to
obtain, then display, a system's IP addresses.
NB: this only works on XP or later versions of Windows.
.NOTES
File Name : Get-IPAddress.ps1
Author : Thomas Lee - [email protected]
Requires : PowerShell V2
.LINK
Script postesd to:
http://www.pshscripts.blogspot.com
MSDN Sample at:
http://msdn.microsoft.com/en-us/library/aa394590(VS.85).aspx
.EXAMPLE
[ps] c:\foo> .\Get-IPAddress.ps1
IP Address : 10.10.1.115
IP Address : fe80::3953:f67b:2f1c:1323
IP Address : 10.10.1.120
IP Address : fe80::d8ed:afe2:2a97:a596
4 IP addresses found on this system
#>
##
# Start of Script
##
# Get Networking Adapter Configuration
$Computer = 'computer'
$IPconfigset = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer
# Iterate and get IP address
$count = 0
foreach ($IPConfig in $IPConfigSet) {
if ($Ipconfig.IPaddress) {
foreach ($addr in $Ipconfig.Ipaddress) {
"IP Address : {0}" -f $addr;
$count++
}
}
}
if ($count -eq 0) {"No IP addresses found"}
else {"$Count IP addresses found on this system"}
#End of Script