Skip to content

Instantly share code, notes, and snippets.

@mritsurgeon
Created October 12, 2021 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mritsurgeon/0fd07ec71048097b613e892d063b8acb to your computer and use it in GitHub Desktop.
Save mritsurgeon/0fd07ec71048097b613e892d063b8acb to your computer and use it in GitHub Desktop.
Add Multiple Veeam backup servers to Veeam Enterprise Manager Script
$list = Import-Csv -Path C:\list.csv
$servers = $list.name
$IPS = $list.Ip
$user = 'administrator'
$pass = 'password'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$logon = Invoke-webrequest -Method "POST" -Uri https://localhost:9398/api/sessionMngr/?v=latest -Headers $Headers
$Response = $logon.Headers
$Sessionkey = $Response.'X-RestSvcSessionId'
$Headers2 = @{
'X-RestSvcSessionId' = $Sessionkey ;
}
foreach ($IP in $IPS)
{
$body = @{
"Description" = "API added backup Server" ;
"DnsNameOrIpAddress" = $IP ;
"Port" = "9392" ;
"Username" = ".\Administrator" ;
"Password" = "password"
}
Invoke-WebRequest -Method 'POST' -Uri https://localhost:9398/api/backupServers?action=create -Headers $Headers2 -Body ($body|ConvertTo-Json) -ContentType "application/json"
}
#Get Backup Servers
#Invoke-WebRequest -Method 'GET' -Uri https://localhost:9398/api/backupServers -Headers $Headers2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment