-
- Service Provider
- Posts: 327
- Liked: 23 times
- Joined: Oct 09, 2012 2:30 pm
- Full Name: Maso
- Contact:
Powershell with EM REST api V10
Hi
In version 9.5 I used to get session and query to rest api as below. But I can't get it to work in V10. How do you use rest api with powershell?
$headers = @{"X-Requested-With"="powershell"}
$baseuri = "https://<EM>:9398/api"
Invoke-RestMethod -Uri "$baseuri/sessionMngr/?v=latest" -Method Post -SessionVariable sess -Credential $credentials
Invoke-RestMethod -Headers $headers -Uri "$baseuri/backupservers" -Method Get -WebSession $sess
\Magnus
In version 9.5 I used to get session and query to rest api as below. But I can't get it to work in V10. How do you use rest api with powershell?
$headers = @{"X-Requested-With"="powershell"}
$baseuri = "https://<EM>:9398/api"
Invoke-RestMethod -Uri "$baseuri/sessionMngr/?v=latest" -Method Post -SessionVariable sess -Credential $credentials
Invoke-RestMethod -Headers $headers -Uri "$baseuri/backupservers" -Method Get -WebSession $sess
\Magnus
-
- VeeaMVP
- Posts: 695
- Liked: 374 times
- Joined: Jun 24, 2019 1:39 pm
- Full Name: Chris Arceneaux
- Location: Georgia, USA
- Contact:
Re: Powershell with EM REST api V10
Hi Magnus,
Key here is Invoke-RestMethod will not work for you during auth as this cmdlet doesn't return response headers. Per our documentation, the Session ID you need is located in the response headers.
As subsequent calls don't require response headers, using Invoke-RestMethod works just fine (see below).
Here's an example of what this would look like:
Key here is Invoke-RestMethod will not work for you during auth as this cmdlet doesn't return response headers. Per our documentation, the Session ID you need is located in the response headers.
As subsequent calls don't require response headers, using Invoke-RestMethod works just fine (see below).
Here's an example of what this would look like:
Code: Select all
# Authorization
$credentials = Get-Credential
$response = Invoke-WebRequest "https://<EM>:9398/api/sessionMngr/?v=latest" -Method Post -Credential $credentials
# Use Session ID for further API calls
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-RestSvcSessionId", $response.Headers["X-RestSvcSessionId"])
$response = Invoke-RestMethod "https://<EM>:9398/api/jobs" -Method Get -Headers $headers
# Show all Jobs
$response.EntityReferences.Ref
-
- Service Provider
- Posts: 327
- Liked: 23 times
- Joined: Oct 09, 2012 2:30 pm
- Full Name: Maso
- Contact:
Re: Powershell with EM REST api V10
Worked great, thanks!
\Magnus
\Magnus
-
- Service Provider
- Posts: 327
- Liked: 23 times
- Joined: Oct 09, 2012 2:30 pm
- Full Name: Maso
- Contact:
Re: Powershell with EM REST api V10
Hi
I can see "UsedQuotaMb" from /vCloud/orgConfigs/<org>. Is it also possible to collect data about number of protected vapps, vms etc? As can be seen in web ui.
\Magnus
I can see "UsedQuotaMb" from /vCloud/orgConfigs/<org>. Is it also possible to collect data about number of protected vapps, vms etc? As can be seen in web ui.
\Magnus
-
- VeeaMVP
- Posts: 695
- Liked: 374 times
- Joined: Jun 24, 2019 1:39 pm
- Full Name: Chris Arceneaux
- Location: Georgia, USA
- Contact:
Re: Powershell with EM REST api V10
Hi Magnus,
Good to hear my previous code samples worked for you.
Following the Job Status section in this post, you can find unique VM IDs of protected workloads during the billing period you're looking for. You'll look for VCD backup jobs (<Platform>vCloud</Platform>) and match their name using the job naming scheme: "<VCD Org Name>_<Tenant Specified Job Name>"
In the future, best to post new questions in a new thread. It makes it easier for newcomers to find answers.
Good to hear my previous code samples worked for you.
Following the Job Status section in this post, you can find unique VM IDs of protected workloads during the billing period you're looking for. You'll look for VCD backup jobs (<Platform>vCloud</Platform>) and match their name using the job naming scheme: "<VCD Org Name>_<Tenant Specified Job Name>"
In the future, best to post new questions in a new thread. It makes it easier for newcomers to find answers.
Who is online
Users browsing this forum: No registered users and 1 guest