-
Notifications
You must be signed in to change notification settings - Fork 0
/
newServer.ps1
50 lines (44 loc) · 1006 Bytes
/
newServer.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
param (
[String]$localPath
)
if (!$localPath) {
$localPath = "."
}
try {
$cred = Import-Clixml -Path "$($localpath)\Credentials_$($env:USERNAME)_$($env:COMPUTERNAME).xml" -ErrorAction Stop -ErrorVariable credentialError
}
catch {
Write-host "Error getting Credential file"
if (!$cred) {
Write-Host "File does not exist."
}
Write-Host $credentialError
Exit
}
try {
$config = Get-Content -Path "$($localpath)\config.json" -ErrorAction Stop -ErrorVariable configError
$config = ($config|ConvertFrom-Json)
}
catch {
Write-host "Error getting config file"
if (!$config) {
Write-Host "File does not exist."
}
Write-Host $configError
Exit
}
$uri = "$($config.url)/addserver"
$body = @{ serverName = $env:COMPUTERNAME }
try {
Invoke-RestMethod `
-uri $uri `
-Credential $cred `
-Method 'POST' `
-Body ($body|ConvertTo-Json) `
-ContentType 'application/json' `
-ErrorAction Stop `
-ErrorVariable postError
}
catch {
Write-Host $postError
}