Skip to content

Instantly share code, notes, and snippets.

@AlexAsplund
Created January 8, 2020 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexAsplund/c9323d37df301fe6e7d4d13da597db81 to your computer and use it in GitHub Desktop.
Save AlexAsplund/c9323d37df301fe6e7d4d13da597db81 to your computer and use it in GitHub Desktop.
Function Add-OpsGenieUser {
[cmdletbinding()]
param(
[parameter(mandatory)]
[string]$UserName,
[parameter(mandatory)]
[string]$FullName,
[parameter(mandatory)]
[string]$Role,
[string]$SkypeUserName,
[string[]]$Tags,
[switch]$InvitationDisabled,
[parameter(mandatory)]
[string]$APIKey,
[string]$APIUri = "https://api.eu.opsgenie.com/v2/users"
)
Begin{
# Create header for authoriation
$Header = @{
Authorization = "GenieKey $APIKey"
}
}
Process {
$Body = [PSCustomObject]@{
username = $UserName
fullName = $FullName
role = @{
name= $Role
}
invitationDisabled = $InvitationDisabled.IsPresent
}
if(![string]::IsNullOrEmpty($SkypeUserName)){
$Body | Add-Member -MemberType NoteProperty -Name "skypeUserName" -Value $SkypeUsername
}
if($null -ne $tags){
$Body | Add-Member -MemberType NoteProperty -Name "tags" -Value $Tags
}
($Body | ConvertTo-Json)
Invoke-RestMethod -ContentType "application/json" -Uri $APIUri -Headers $Header -Method Post -Body ($Body | ConvertTo-Json)
}
End {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment