Initial commit with Autotask/DRMM
This commit is contained in:
41
tools/autotask.ps1
Normal file
41
tools/autotask.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
function Invoke-AutotaskProvision {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string]$CompanyName,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$PhoneNumber,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[hashtable]$Credentials
|
||||
)
|
||||
|
||||
if (-not $Credentials["AutotaskURL"] -or -not $Credentials["AutotaskIntCode"] -or -not $Credentials["AutotaskUsername"] -or -not $Credentials["AutotaskSecret"]) {
|
||||
throw "Missing Autotask credentials in hashtable."
|
||||
}
|
||||
|
||||
$BaseURL = $Credentials["AutotaskURL"]
|
||||
$Url = "https://$BaseURL/atservicesrest/v1.0/companies"
|
||||
|
||||
$Headers = @{
|
||||
"ApiIntegrationcode" = $Credentials["AutotaskIntCode"]
|
||||
"UserName" = $Credentials["AutotaskUsername"]
|
||||
"Secret" = $Credentials["AutotaskSecret"]
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
|
||||
$Body = @{
|
||||
companyName = $CompanyName
|
||||
companyType = 1
|
||||
phone = $PhoneNumber
|
||||
ownerResourceID = 4
|
||||
} | ConvertTo-Json -Depth 3
|
||||
|
||||
try {
|
||||
$Response = Invoke-RestMethod -Uri $Url -Method Post -Headers $Headers -Body $Body
|
||||
$CompanyID = $Response.itemId, $Response.id, $Response.companyID, $Response.item.id | Where-Object { $_ } | Select-Object -First 1
|
||||
[System.Windows.MessageBox]::Show("Autotask company created with ID: $CompanyID", "Autotask")
|
||||
} catch {
|
||||
throw "[Autotask] Provisioning failed: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user