-
- Novice
- Posts: 4
- Liked: 1 time
- Joined: May 22, 2024 10:19 am
- Full Name: Franz Levy
- Contact:
Enterprise Manager API via Powershell
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
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
-
- Veeam Software
- Posts: 2331
- Liked: 554 times
- Joined: Jun 28, 2016 12:12 pm
- Contact:
Re: Enterprise Manager API via Powershell
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.
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
-
- Novice
- Posts: 4
- Liked: 1 time
- Joined: May 22, 2024 10:19 am
- Full Name: Franz Levy
- Contact:
Re: Enterprise Manager API via Powershell
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.
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.
-
- Veeam Software
- Posts: 2015
- Liked: 671 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: Enterprise Manager API via Powershell
Hi Franz,
Is it possible that you share your script here omitting all the private data?
Best regards,
Oleg
Is it possible that you share your script here omitting all the private data?
Best regards,
Oleg
-
- Novice
- Posts: 4
- Liked: 1 time
- Joined: May 22, 2024 10:19 am
- Full Name: Franz Levy
- Contact:
Re: Enterprise Manager API via Powershell
Hi Oleg,
Please see below my script:
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
Reason: Edited to add code-blocks for the script
-
- Veeam Software
- Posts: 2331
- Liked: 554 times
- Joined: Jun 28, 2016 12:12 pm
- Contact:
Re: Enterprise Manager API via Powershell
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?)
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
-
- Novice
- Posts: 4
- Liked: 1 time
- Joined: May 22, 2024 10:19 am
- Full Name: Franz Levy
- Contact:
Re: Enterprise Manager API via Powershell
Hi David,
Sory for the delay in my response.
There are not errors with $responseJobs, it is just empty.
I edited the script without saving the results please see the response below:
PS C:\Windows\system32> Invoke-RestMethod 'https://#####:9398/api/jobs' -Method 'GET' -Headers $headerswithsession
xml EntityReferences
--- ----------------
version="1.0" encoding="utf-8" EntityReferences
I believe the jobs im expecting are within that URL, I tested via postman while writing the script
Sory for the delay in my response.
There are not errors with $responseJobs, it is just empty.
I edited the script without saving the results please see the response below:
PS C:\Windows\system32> Invoke-RestMethod 'https://#####:9398/api/jobs' -Method 'GET' -Headers $headerswithsession
xml EntityReferences
--- ----------------
version="1.0" encoding="utf-8" EntityReferences
I believe the jobs im expecting are within that URL, I tested via postman while writing the script
-
- Veeam Software
- Posts: 2331
- Liked: 554 times
- Joined: Jun 28, 2016 12:12 pm
- Contact:
Re: Enterprise Manager API via Powershell
Hi Franz,
It looks like it returned an XML object -- save it to a variable and check the EntityReferences property, doesn't it have a bit more information for you?
It looks like it returned an XML object -- save it to a variable and check the EntityReferences property, doesn't it have a bit more information for you?
David Domask | Product Management: Principal Analyst
Who is online
Users browsing this forum: No registered users and 2 guests