I'm attempting to write a PowerShell script that will automate the process of adding new user accounts to our Jira instance. I've provided my code but I'm honestly not even getting to that point as I am receiving a 401 error:
This resource requires WebSudo.
I have seen these two posts on the Jira support forum but it's not clear to me how I could adapt the code to get and then apply it to my REST call. I would be fine with changing this to use the .Net WebClient class if that would make all of this easier, but right now I'm at a bit of a loss.
$url = "https://devjira.domain.com/rest/api/2/user"
$user = "admin"
$pass = "super secure password"
$secpasswd = ConvertTo-SecureString $user -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($pass, $secpasswd);
$userObject = @{
    name     = "rkaucher@domain.net";
    emailAddress = "robert_kaucher@domain.com";
    displayName  = "Bob Kaucher";
    notification = $true;
}
$restParameters = @{
    Uri = $url;
    ContentType = "application/json";
    Method = "POST";
    Body = (ConvertTo-Json $userObject).ToString();
    Credential = $cred;
}
Invoke-RestMethod @restParameters
JSON output
{
    "name":  "rkaucher@domain.net",
    "displayName":  "Bob Kaucher",
    "emailAddress":  "robert_kaucher@domain.com",
    "notification":  true
}
 
    