monnens
(Monnens)
1
Has anyone already used the SCOM 1801 rest api? We’re struggling with authentication:
$scomHeaders = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$scomHeaders.Add(‘Content-Type’,‘application/json’)
$scomCreds = Get-Credential
$uriBase = ‘https://xxxx.xxx.xx/OperationsManager/authenticationMode’
Invoke-RestMethod -Method get -Uri $uriBase -Credential $scomCreds
Returns ‘Windows’ so I guess I’m authenticated (without credential this gives a 401)
$uriBase = ‘https://xxxx.xxx.xx/OperationsManager/authenticate’
Invoke-RestMethod -Method Post -Uri $uriBase -Credential $scomCreds
Returns 401
Thanks in advance!!
rem-8
(Rem-8)
2
Does your account have Author or Advanced Operator or Admin rights? It looks like it uses an Operator role for this.
Hi, I finally got it working.
Here a code example:
$scomHeaders = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$scomHeaders.Add(‘Content-Type’,‘application/json; charset=utf-8’)
$bodyraw = “Windows”
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json
$uriBase = ‘http://xxxxxx/OperationsManager/authenticate’
$auth = Invoke-RestMethod -Method POST -Uri $uriBase -Headers $scomheaders -body $jsonbody -UseDefaultCredentials -SessionVariable websession
$query = @($query = @( @{ “classid” = “” “displayColumns”= “severity”, “monitoringobjectdisplayname”, “name”, “age”, “repeatcount”, “lastModified” })
$jsonquery = $query | ConvertTo-Json
$Response = Invoke-WebRequest -Uri “http://xxxxxx/OperationsManager/data/alert” -Method Post -Body $jsonquery -ContentType “application/json” -UseDefaultCredentials -WebSession $websession
$alerts = ConvertFrom-Json -InputObject $Response.Content
$alerts.rows | select monitoringobjectdisplayname,name,severity,age
Julien Martin,
Thank you for your examples!
Do you have an example of the “Retrieve Performance Data” API call? I am having trouble with that.
Thanks in advance.
Kind Regards
Thijs
monnens
(Monnens)
5
The account got admin rights in SCOM.