-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_server_info.ps1
77 lines (61 loc) · 1.97 KB
/
get_server_info.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
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
param (
[Parameter(Position=0)]
[string]
$server,
[string]
$inputFile,
[string]
$outputFile
)
[System.Collections.ArrayList]$entries = @()
$count = 0 # Progress Bar counter
if ($inputFile){
$hosts = Get-Content -Path $inputFile -Encoding UTF8
}
else {
$hosts = @($server)
}
foreach ($hostName in $hosts) {
# Remove port from hostName to use HTTPS protocol in legacy server lists
$hostName = $hostName -replace ":8080" -replace ":9080"
Write-Progress -Activity "Checking hosts..." -Status "Progress:" -PercentComplete ($count/$hosts.Length*100) -CurrentOperation $hostName
# Skip commented strings
if ($hostName[0] -eq '#') {
$count += 1
continue
}
try {
$request = Invoke-WebRequest -Uri https://$hostName/resto/get_server_info.jsp -Method Get -ErrorAction Continue
$content = $request.Content
$serverName = Select-XML -Content $content -XPath "r/serverName"
$version = Select-XML -Content $content -XPath "r/version"
$serverState = Select-XML -Content $content -XPath "r/serverState"
}
catch {
$serverName = "N/A"
$version = "N/A"
$serverState = "N/A"
}
$entryDict = [ordered]@{
HostName = $hostName
ServerName = $serverName
Version = $version
ServerState = $serverState
}
# Create psobject to store result fields as properties
$entry = New-Object psobject
$entry | Add-Member -NotePropertyMembers $entryDict
# Add entry into $entries ArrayList silently
$entries.Add($entry) | Out-Null
$count += 1
}
Write-Output $entries | Format-Table -AutoSize
# Export entry as CSV if "-outputFile" is specified. Remove if file
if ($outputFile) {
if (Test-Path $outputFile) {
Remove-Item $outputFile
}
foreach ($entry in $entries) {
Export-Csv -InputObject $entry -Path $outputFile -Append -Encoding UTF8 -Delimiter ";" -Force -NoTypeInformation
}
}