-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportImport-WacConnections.ps1.txt
38 lines (34 loc) · 1.69 KB
/
ExportImport-WacConnections.ps1.txt
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
#================================
$WacSourceServer = "azs-mgmt"
$WacDestinServer = "azs-wac-demo"
$TagValue = "Automatically_Migrated"
#================================
#Ignore self signed certificates
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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12
#Retrieve connection cfg from source wac
$SourceConnections = Invoke-RestMethod -Method Get -Uri ("https://" + $WacSourceServer + "/api/connections") -ErrorAction SilentlyContinue -UseDefaultCredentials
if($null -ne $SourceConnections) {
foreach($Connection in $SourceConnections.Value) {
$ConnectionProperties = $Connection.Properties
if($null -ne $ConnectionProperties.tags) {
$ConnectionProperties.tags += $TagValue
} else {
Add-Member -InputObject $ConnectionProperties -NotePropertyName "tags" -NotePropertyValue @($TagValue)
}
$ConnectionProperties = ConvertTo-JSON -InputObject $ConnectionProperties
$Body = "[" + $ConnectionProperties + "]"
Invoke-RestMethod -Method Put -Uri ("https://" + $WacDestinServer + "/api/connections") -Body $Body -ErrorAction SilentlyContinue -UseDefaultCredentials
}
}