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)"
|
||||
}
|
||||
}
|
||||
55
tools/dattormm.ps1
Normal file
55
tools/dattormm.ps1
Normal file
@@ -0,0 +1,55 @@
|
||||
function Invoke-DattoProvision {
|
||||
param (
|
||||
[Parameter(Mandatory)]
|
||||
[string]$CompanyName,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[hashtable]$Credentials
|
||||
)
|
||||
|
||||
if (-not $Credentials["DattoURL"] -or -not $Credentials["DattoKey"] -or -not $Credentials["DattoSecret"]) {
|
||||
throw "Missing Datto RMM credentials in hashtable."
|
||||
}
|
||||
|
||||
$TokenUrl = "$($Credentials["DattoURL"].TrimEnd('/'))/auth/oauth/token"
|
||||
$SiteUrl = "$($Credentials["DattoURL"].TrimEnd('/'))/api/v2/site"
|
||||
|
||||
$TokenBody = @{
|
||||
grant_type = "password"
|
||||
username = $Credentials["DattoKey"]
|
||||
password = $Credentials["DattoSecret"]
|
||||
}
|
||||
|
||||
$TokenHeaders = @{
|
||||
"Content-Type" = "application/x-www-form-urlencoded"
|
||||
"Accept" = "application/json"
|
||||
}
|
||||
|
||||
try {
|
||||
# Construct Basic Auth manually
|
||||
$pair = "public-client:public"
|
||||
$bytes = [System.Text.Encoding]::UTF8.GetBytes($pair)
|
||||
$base64 = [System.Convert]::ToBase64String($bytes)
|
||||
$TokenHeaders["Authorization"] = "Basic $base64"
|
||||
|
||||
$TokenResponse = Invoke-RestMethod -Uri $TokenUrl -Method Post -Headers $TokenHeaders -Body $TokenBody
|
||||
$AccessToken = $TokenResponse.access_token
|
||||
} catch {
|
||||
throw "[Datto] Token request failed: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
$SiteHeaders = @{
|
||||
"Authorization" = "Bearer $AccessToken"
|
||||
"Content-Type" = "application/json"
|
||||
"Accept" = "application/json"
|
||||
}
|
||||
|
||||
$SiteBody = @{ name = $CompanyName } | ConvertTo-Json -Depth 3
|
||||
|
||||
try {
|
||||
$SiteResponse = Invoke-RestMethod -Uri $SiteUrl -Method Put -Headers $SiteHeaders -Body $SiteBody
|
||||
[System.Windows.MessageBox]::Show("Datto RMM site created: $CompanyName", "Datto RMM")
|
||||
} catch {
|
||||
throw "[Datto] Site creation failed: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user