Created
January 8, 2020 15:55
-
-
Save AlexAsplund/c9323d37df301fe6e7d4d13da597db81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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