RESTful knowledge exchange
Post Reply
Franz.L
Novice
Posts: 3
Liked: never
Joined: May 22, 2024 10:19 am
Full Name: Franz Levy
Contact:

Enterprise Manager API via Powershell

Post by Franz.L »

Hi there,

I have an Enterprise manager where I would like to pull reporting via powershell. I get my script to connect to the api and get a session ID but i cant seem to pull any data such as the VM that is being backed up, the status of the backup and the last run.

Any suggestion on a script that can pull this type of report?

Thanks
david.domask
Veeam Software
Posts: 1425
Liked: 365 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Enterprise Manager API via Powershell

Post by david.domask »

Hi Franz, welcome to the forums.

https://helpcenter.veeam.com/docs/backu ... ml?ver=120

This would be probably your best starting endpoint to get Session data; what sort of issues were you facing with your script? Similarly, how many Veeam Backup and Replication servers are connected to your Enterprise Manager installation? The reason I ask is that if it's just 1 or 2, it might be better to just use the Veeam Powershell cmdlets instead and report directly from Veeam Backup and Replication -- If you search a bit on our Powershell forums, you likely can find a script that meets your needs or piece one together.
David Domask | Product Management: Principal Analyst
Franz.L
Novice
Posts: 3
Liked: never
Joined: May 22, 2024 10:19 am
Full Name: Franz Levy
Contact:

Re: Enterprise Manager API via Powershell

Post by Franz.L »

Hi David,

Thank you for your response.

The issue I face with my script is that after successfully connecting to the EM and the api, retrieving the session ID, I try to retrieve the job Information but the script says there are no jobs. That being said, I am by no means a PS expert and what I have accomplished thus far gas taken a lot of trial and error so its probably something in the script that just doesnt work.

I currently have 5 VBR servers connected to this EM (With more to come) and I will also be building other 3 EM servers with more VBR servers.

Thanks for the help.
oleg.feoktistov
Veeam Software
Posts: 1953
Liked: 645 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Enterprise Manager API via Powershell

Post by oleg.feoktistov »

Hi Franz,

Is it possible that you share your script here omitting all the private data?

Best regards,
Oleg
Franz.L
Novice
Posts: 3
Liked: never
Joined: May 22, 2024 10:19 am
Full Name: Franz Levy
Contact:

Re: Enterprise Manager API via Powershell

Post by Franz.L »

Hi Oleg,

Please see below my script:

Code: Select all

$vemServer = ###
$username = ###
$password = "####

$encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${username}:${password}"))

$vemServer = "###"
$vemServer = $vemServer.TrimEnd('/')  # Remove any trailing slashes

$username = ###
$password = ###

$encodedCredentials = "Basic "+ [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${username}:${password}"))

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $encodedCredentials)

# $headers.Add("Cookie", "X-RestSvcSessionId=###")

$response = Invoke-WebRequest 'https://###/api/sessionMngr/?v=latest' -Method 'POST' -Headers $headers 
$sessionid =$response.Headers.'X-RestSvcSessionId'

$headerswithsession = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headerswithsession.Add("X-RestSvcSessionId", $sessionid)


$responsejobs = Invoke-RestMethod 'https://####:9398/api/jobs' -Method 'GET' -Headers $headerswithsession
$responsejobs
Last edited by david.domask on May 28, 2024 10:25 am, edited 1 time in total.
Reason: Edited to add code-blocks for the script
david.domask
Veeam Software
Posts: 1425
Liked: 365 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Enterprise Manager API via Powershell

Post by david.domask »

Hi Franz,

Is there any error you get or does $responsejobs just end up empty (or it has a response but there is no job data in the rest response?)

Can you maybe check each variable you're saving the results to and try the Invoke-RestMethod without saving it to a variable? What is in the response or does the API return any errors? (also, as just a sanity check, [url=https://helpcenter.veeam.com/docs/backu ... ver=120see the note on the /jobs endpoint[/url], the jobs you're expecting are within those types returned?)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests