- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2019 01:54 PM
Is there an exanple for using PowerShell to create an ITOM event using the API via a Mid Server?
Solved! Go to Solution.
- Labels:
-
Event Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2019 11:10 AM
Hi Nigel,
Please find below an example:
function Get-BasicAuthCreds {
param([string]$Username,[string]$Password)
$AuthString = "{0}:{1}" -f $Username,$Password
$AuthBytes = [System.Text.Encoding]::Ascii.GetBytes($AuthString)
return [Convert]::ToBase64String($AuthBytes)
}
$BasicCreds = Get-BasicAuthCreds -Username "evt.integration" -Password "ServiceN0w!"
$body = '{ "records":
[
{
"source":"SCOM",
"event_class":"SCOM 2007 on scom.server.com",
"resource":"C:",
"node":"name.of.node.com",
"metric_name":"Percentage Logical Disk Free Space",
"type":"Disk space",
"severity":"4",
"description":"The disk C: on computer V-W2K8-dfg.dfg.com is running out of disk space. The value that exceeded the threshold is 41% free space.",
"additional_info":""
}
]
}'
Invoke-WebRequest -Uri "http://localhost:9082/api/mid/em/jsonv2" -Headers @{"Authorization"="Basic $BasicCreds"} -ContentType "application/json" -Method Post -Body $body

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 10:46 AM
Hi natasciaheil,
No.. This is a bad practice when it comes to Event Management, you should either:
a. Post event against the instance Event Management web service API
https://<instancename>.service-now.com/api/global/em/jsonv2
b. Post event against MID WebService Event Collector
http://{MID_Server_IP}:{MID_Web_Server_Port}/api/mid/em/jsonv2
Regards
Jef
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 11:29 PM
Thanks for this clarification.
Nat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2019 05:31 AM
Jef,
Quick question for you why is it best practice to use that API? What makes it any different then going directly to the event table? I'm not saying you are wrong I am just curious the reason for this as I've never been able to get that answered by someone. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2022 03:01 PM
Thanks for the response. Is there an example using API Key Credentials?