- 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-09-2019 05:41 AM
Nigel,
I have an example somewhere but have to track it down. I'll try to find it by end of day and post an example here. Thanks.

- 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-14-2019 12:24 PM
Thanks for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 06:07 AM
I would recommend to directly write the event with the Table api into the event table:
# Eg. User name="admin", Password="admin" for this code sample. $user = "admin" $pass = "admin" # Build auth header $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass))) # Set proper headers $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo)) $headers.Add('Accept','application/json') $headers.Add('Content-Type','application/json') # Specify endpoint uri $uri = "https://xxx.service-now.com/api/now/table/em_event" # Specify HTTP method $method = "post" # Specify request body {request.body ? "$body = \"" :""}}{\"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.\"}" # Send HTTP request $response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body $body # Print response $response.RawContent
Regards,
Natascia