Import/Export Domain Admin Configurations in Ambience 4.x via PowerShell

This is an example of how to Import/Export configurations from the Domain Admin by calling Ambience Server API using PowerShell.

1. Export Domain Configurations

Notes:
// Do change the following text/value accordingly.
[Username], [Password], [cookie-name], [cookie-value], [cookie-domain], [file-name]

API Structure:
[protocol] :[host] :[port] /elx/dm/[domain] /vivace/export-content/

For example,
http://localhost:8080/elx/dm/eno/vivace/export-content/

PowerShell cmdlet to download configurations:

$uri = 'http://localhost:8080/elx/dm/eno/vivace/export-content/'
$User = "[Username]"
$Pw = "[Password]"
$base64AuthInfo =
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($User):$($Pw)"))
$Header = @{
     Authorization = "Basic $base64AuthInfo"
}
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "[cookie-name]"
$cookie.Value = "[cookie-value]"
$cookie.Domain = "[cookie-domain]"
$session.Cookies.Add($cookie);
Invoke-WebRequest $uri -Headers $Header -Method Post -WebSession $session
-OutFile [file-name].xml -Verbose

2. Import Domain Configurations

Notes:
// Do change the following text/value accordingly.
[Username], [Password], [cookie-name], [cookie-value], [cookie-domain], [file-name], [path-to-file]

API Structure:
[protocol]:[host]:[port]/elx/dm/[domain]/vivace/import-content/

For example,
http://localhost:8080/elx/dm/eno/vivace/import-content/

PowerShell cmdlet to upload configurations:

$uri = "http://localhost:8080/elx/dm/eno/vivace/import-content/"
$FilePath = "[path-to-file]"
$User = "[Username]"
$Pw = "[Password]"
$base64AuthInfo =
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($User):$($Pw)"))
$Header = @{
     Authorization = "Basic $base64AuthInfo"
}
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "[cookie-name]"
$cookie.Value = "[cookie-value]"
$cookie.Domain = "[cookie-domain]"
$session.Cookies.Add($cookie);
$fileBytes = [System.IO.File]::ReadAllBytes($FilePath);
$fileEnc =
[System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);
$boundary = [System.Guid]::NewGuid().ToString();
$LF = "`r`n";
$bodyLines = (
     "--$boundary",
     "Content-Disposition: form-data; name=`"file`";
     filename=`"[file-name].xml`"",
     "Content-Type: application/octet-stream$LF",
     $fileEnc,
     "--$boundary--$LF"
) -join $LF
Invoke-RestMethod -Uri $uri -Method Post -ContentType "multipart/form-data;
boundary=`"$boundary`"" -Body $bodyLines -Credential $credential -WebSession
$session

Download Documentation here:
Import-Export-DM-Powershell.pdf (57.6 KB)

Additional Resources:
cmdlet-format.zip (1.3 KB)