-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ComputerOnLine.ps1
More file actions
136 lines (100 loc) · 3.14 KB
/
Get-ComputerOnLine.ps1
File metadata and controls
136 lines (100 loc) · 3.14 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
##################################################################################
#
#
# Script name: Get-ComputerOnline.ps1
# Author: goude@powershell.nu
# Homepage: www.powershell.nu
#
#
##################################################################################
param ([string]$Computer, [string]$List, [switch]$help, [switch]$Windows7)
function GetHelp() {
$HelpText = @"
DESCRIPTION
NAME: Get-ComputerOnline.ps1
Gets Information about Clients that are
in your network and returns the information
to a HashTable Array
PARAMETERS:
-Computer Sharepoint Url (Optional)
-List Exports the Information to a Csv file (Optional)
-Windows7 Use this switch if run the script on Vista Or Win 7 (optional)
-help Prints the HelpFile (Optional)
SYNTAX:
./Get-ComputerOnline.ps1 -Computer Laptop1
Checks if the Computer is on the Network and returns
Computername and IPAddress.
./Get-ComputerOnline.ps1 -List "C:\Folder\MyComputerList.txt"
Loops through each Client in the List and checks
if the Computers are on the Network and returns
Computername and IPAddress
./Get-ComputerOnline.ps1 -Computer Laptop1 -Windows7
Checks if the Computer is on the Network and returns
Computername and IPAddress for Windows 7 Computers,
If they use IPV4
./Get-ComputerOnline.ps1 -List "C:\Folder\MyComputerList.txt" -Windows7
Loops through each Client in the List and checks
if the Computers are on the Network and returns
Computername and IPAddress for Windows 7 Computers,
If they Use IPV4
./Get-ComputerOnline.ps1 -help
Displays the help topic for the script
"@
$HelpText
}
function Collect-Information($Computer, $List, [switch]$Windows7) {
if($Windows7) {
if($List) {
$GetList = Get-Content $List
$GetList | ForEach {
Get-IP $_ -Windows7
}
} else {
Get-IP $Computer -Windows7
}
} else {
if($List) {
$GetList = Get-Content $List
$GetList | ForEach {
Get-IP $_
}
} else {
Get-IP $Computer
}
}
}
function Get-IP([string]$Computer, [switch]$Windows7) {
$ClientObject = @{}
if($Windows7) {
$Ping = ping -4 $Computer
} else {
$Ping = ping $Computer
}
if($Ping -match "Reply from") {
$IP = ($Ping | Select-String "Reply from")[0].ToString()
$IPAddress = [regex]::Match($IP,"[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*")
# Add Information to a Hasthtable Array
$ClientObject.Add("Computer",$Computer)
$ClientObject.Add("IPAddress",$IPAddress)
$ClientObject.Add("Online","Yes")
} else {
# Add Information to a Hasthtable Array
$ClientObject.Add("Computer",$Computer)
$ClientObject.Add("IPAddress","Not Found")
$ClientObject.Add("Online","No")
}
$ClientObject
}
if ($help) { GetHelp }
if ($Computer -AND $List) {
Write-Host "Please Specify a Client OR a List containing Clients";
GetHelp
Continue
}
if ($Windows7) {
if ($Computer) { Collect-Information -Computer $Computer -Windows7 }
if ($List) { Collect-Information -List $List -Windows7 }
} else {
if ($Computer) { Collect-Information -Computer $Computer }
if ($List) { Collect-Information -List $List }
}