From a1a4a7882060ac41fe5c262d9ae1ada3c576e18b Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 3 Jun 2019 07:11:20 -0400 Subject: [PATCH] Create Connect-ZertoAnalytics.ps1 --- .../Public/Connect-ZertoAnalytics.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ZertoApiWrapper/Public/Connect-ZertoAnalytics.ps1 diff --git a/ZertoApiWrapper/Public/Connect-ZertoAnalytics.ps1 b/ZertoApiWrapper/Public/Connect-ZertoAnalytics.ps1 new file mode 100644 index 0000000..698d957 --- /dev/null +++ b/ZertoApiWrapper/Public/Connect-ZertoAnalytics.ps1 @@ -0,0 +1,19 @@ +function Connect-ZertoAnalytics { + [cmdletbinding()] + param( + [Parameter( + Mandatory = $true, + HelpMessage = "PSCredential Object containing username and password authorized for the Zerto Analytics site", + Position = 0 + )] + [System.Management.Automation.PSCredential]$credential + ) + + $uri = "auth/token" + Set-Variable -Name zaHeaders -Scope Script -Value @{"Accept" = "application/json" } + Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks + $body = @{"username" = $credential.UserName; "password" = $credential.GetNetworkCredential().password } + $result = Invoke-ZARestRequest -Uri $uri -body $($body | ConvertTo-Json) -Method POST + $Script:zaHeaders["Authorization"] = "Bearer $($result.Token)" + $Script:zaHeaders +} \ No newline at end of file