-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-Com-Servers.ps1
75 lines (57 loc) · 2.45 KB
/
Get-Com-Servers.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
<#
Legal Disclaimer
This script is an example script and is not supported by any means.
The author further disclaim all implied warranties including,
without limitation, any implied warranties of merchantability
or of fitness for a particular purpose.
In no event shall its authors or anyone else involved in
the creation, production or delivery of the scripts be liable for
any damages whatsoever
(including, without limitation, damages for loss of business profits, business interruption,
loss of business information, or other pecuniary loss) arising out of the use of or the inability
to use the sample scripts or documentation,
even if the author has been advised of the possibility of such damages.
The entire risk arising out of the use or performance of the sample scripts
and documentation remains with you.
#>
<#
The Author is Loompas0 who is a pseudo.
The source site of the code couldbe https://github.com/loompas0/
if you are explicitely or implicitely authorized to access to it.
#>
<#This script has been tested on a Windows environment#>
# History
# - 11/14/2023 creation and first tests
# ==============================================================
# Use the Connection script called "Connect-COM-Secret.ps1"
# This file should be located in the same Directory as this script
# use json file to connect to all sites and retrieve the token and header created
. ./Connect-COM-Secret.ps1
# Now that we have a token because of successfull COM authentication, we can proceed with REST API calls
# First prepare the environnement
$ConnectivityEndPoint = $ComEndpoint
$ConnectivityUri = "/compute-ops/v1beta2/servers?offset=0&limit=100"
$headers = @{}
$headers["Authorization"] = "Bearer $AccessToken"
# Api call to GLR
$request = @{
Headers = $headers
StatusCodeVariable = "statusCode"
Method = "GET"
URI = $ConnectivityEndpoint + $ConnectivityUri
}
# Invoke the Api Call
try {
$result = Invoke-RestMethod @request
}
catch {
Write-Error "Error making API call to GLDR" -ErrorAction Stop
}
# Show the result in json format
$resultJson = ConvertTo-Json $result
write-output $resultJson
# Write the result in a Json formatted file called ComServers.Json
Set-Content -Path './ComServers.json' $resultJson
# Show some information in more readeable format. as a table
Write-Host "All Servers visbible in Com are : " -ForegroundColor Yellow
$result.items.hardware | Select-Object serialNumber , model, productId | format-table