REST API knowledge exchange
Post Reply
matteu
Veeam Legend
Posts: 821
Liked: 128 times
Joined: May 11, 2018 8:42 am
Contact:

Help for powershell Report Enterprise manager

Post by matteu »

Hello,

I would like to automate some task like export my veeam configuration with powershell.
I have a list with all information I would like to obtain on my Enterprise manager :

Licence - socket - instance - agent licence usage - expiration licence date
Version veeam enterprise manager
Veeam managed server connected to EM + account used
vcenters connected to vcenter with version
AD account used for Exchange restore
RBAC what account are used and what roles they have
Is file configuration backup protected with EM
Settings for SAML authentication
SMTP settings
URL EM
URL selfservice

I know a little how powershell works but I never use it with API.
I read Veeam documentation but it's not enough for me to understand how I can do.

I did some research and I found this website with some excellent explanation : http://blog.dewin.me/2016/04/veeam-rest ... shell.html

Unfortunately, I don't understand enough how to do. I tried to find for RBAC to see account with the role but I don't know how to do.
I can find all my account with theses steps but what I have to do after ? :

Code: Select all

$VBEMServerName="veeam.production.lan"

$r_api = Invoke-WebRequest -Method Get -Uri "https://$($VBEMServerName):9398/api/"
$r_api_xml = [xml]$r_api.Content
$r_api_links = "https://$($VBEMServerName):9398/api/sessionMngr/?v=latest"
$r_login = Invoke-WebRequest -method Post -Uri $r_api_links -Credential $credentials

#get session id which we need to do subsequent request
$sessionheadername = "X-RestSvcSessionId"
$sessionid = $r_login.Headers[$sessionheadername]

#content
$r_login_xml = [xml]$r_login.Content
$r_login_links = $r_login_xml.LogonSession.Links.Link
$joblink = "https://$($VBEMServerName):9398/api/security/accounts"

#get jobs with id we have
$r_jobs = Invoke-WebRequest -Method Get -Headers @{$sessionheadername=$sessionid} -Uri $joblink
$r_jobs_xml = [xml]$r_jobs.Content
$r_job = $r_jobs_xml.EntityReferences.Ref 
$r_job_alternate = $r_job.links.link 
Finally, Is there an easier way than powershell to see all the xml ? In veeam documentation it's well formated but when I do it with powershell, it's not the same display.

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

Re: Help for powershell Report Enterprise manager

Post by oleg.feoktistov » 1 person likes this post

Hi,

Licence usage - not exposed through API.
EM Version - not exposed, but you can get a version of backup servers connected: send GET to /backupServers/{id}?format=Entity
Managed servers connected to EM - Not sure what you mean. If those connected to VBR instances: send GET to /managedServers.
If backup servers managed by EM: send GET to /backupServers. + accounts used - not available.
vCenters connected + version - No info on version, but you can get the list: send GET to /hierarchyRoots. You are after those of VC type.
AD account used for Exchange restore - not available.
Accounts and roles - explore /security/accounts and /security/accounts/{id}/roles endpoints with GET requests.
Is file configuration backup protected with EM - I'm not sure what you mean by that. Could you, please, elaborate?
Settings for SAML authentication - not implemented.
SMTP settings - not implemented.
EM URL - Not sure why you need to get it through API as it should be already presented in your request. Otherwise, you can get it, for instance, from the response on session creation request. Look for first Link's href property. Example:

Code: Select all

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Basic <sessionToken>")
$headers.Add("Cookie", "X-RestSvcSessionId=<sessionToken>")

$response = Invoke-RestMethod 'https://<enterpriseManagerURL>/api/sessionMngr/?v=latest' -Method 'POST' -Headers $headers
$response.Links[0].Href
Then you can just split the ip address/dns name.
Self-Service Portal URL - not exposed.
Is there an easier way than powershell to see all the xml ?
Can you, please, show how it is exactly not well formatted in your case? What's powershell version you are using?

On a side note - I'd recommend to use Postman when exploring and testing APIs. It provides great visibility on your requests and gives request examples in many programming languages, including powershell framework.

Thanks,
Oleg
matteu
Veeam Legend
Posts: 821
Liked: 128 times
Joined: May 11, 2018 8:42 am
Contact:

Re: Help for powershell Report Enterprise manager

Post by matteu »

Hello,

Thank you very much for your answer.
For the elements not implemented. Where can I obtain this information ?
Do I need to use SQL to obtain all information I would like ?

I often do customer audit and I would like to automate this process to avoid print screen and lost time on all windows sections.
I'm trying to write powershell script for VBR but for EM it's a lot of harder. Maybe Powershell is not the good way to do it for this element and SQL should be ?
What do you think ?

Is file configuration backup protected with EM : When you backup configuration file on veeam server, if you lost password you can use EM as backup solution.
EM URL : You're right it's useless because we know it while we use it for the API.

I just find it's possible to explore API with web browser with this link : https://serverName:9398/web
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Help for powershell Report Enterprise manager

Post by oleg.feoktistov » 1 person likes this post

Hi,

Just to clarify - Enterprise Manager doesn't have Powershell module, so Powershell here is just a client, which talks to REST API controllers.

Of course, you can get all the data querying EM DB directly using raw SQL or ORM libraries. However, I must note that:

1. It is not an official way to interact with EM, so it is not supported. Plus any internal changes to the EM DB table structure, behaviour etc. would 99% cause the need to rewrite your code.
2. It might feel convenient up to the moment, when you need to audit creation/deletion requests: Some API controllers write information to several tables at once. So, sending requests via REST, in most of the cases you would have a single entry point per resource. While interacting with EM DB directly, you would need to determine tables used in every case and manually populate them.
3. Points above would most likely lead to unexpected behaviour and bugs you wouldn't experience with official API.
When you backup configuration file on veeam server, if you lost password you can use EM as backup solution.
This feature is also not implemented in EM REST.

I noted all the not implemented items as feature requests for EM REST API.
Future actions and prioritization would depend on features' demand.

Thanks,
Oleg
matteu
Veeam Legend
Posts: 821
Liked: 128 times
Joined: May 11, 2018 8:42 am
Contact:

Re: Help for powershell Report Enterprise manager

Post by matteu »

Thank you very much for you answer.
Your posts are very usefull for me.

Unfortunately, I can see I don't have any possibility now to do what I would like.
Rest API on EM is not enough complete and SQL query are not a good idea.

I will do it with print screen until maybe REST api become more interesting to my needs.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests