enlanguageRegister | Login

Automate IT tasks easily and efficiently

addy · resource scripting

PowerShell script template for admins buddy resources

Turn any existing PowerShell script into a ready-to-run admins buddy resource — copy the template, keep the header and footer, and drop in your own automation logic.

No account needed to read this page. Register once you’re ready to publish your first resource.

Also see: Datasets — load credentials securely in scripts

How it works

Built specifically for admins buddy automation

admins buddy is a PowerShell-first automation platform. This template gives every new resource script the same reliable starting point.

Header & footer included

Every template ships with a header and footer built for admins buddy, so your script talks to the platform correctly from the first run.

Placeholders that just work

Placeholders in the header and footer take the parameters from admins buddy and format the output the way the platform expects.

Bring your own logic

Replace the body with your own PowerShell code and swap the parameter placeholders for your resource's inputs — the template covers a wide range of automation scenarios.

Reference

PowerShell script template

Copy the template below into a new resource script, then customize the body and parameters for your workflow.

_powershell-template.ps1
[CmdletBinding()]
Param(
    [Parameter(Mandatory=$false)]
    [string]$installPath="not-set",
    [Parameter(Mandatory=$false)]
    [string]$jobId="not-set",
    [Parameter(Mandatory=$false)]
    [string]$action="not-set"
)

$debugScript = 0;
if ($debugScript -eq 1) {
    write-host "debugging mode on" -f yellow
    $installPath = "C:\addy\" #Debugging
    $jobId = "jobXXXXXXX" #only for debugging
}
$ErrorActionPreference = 'Continue'

# Only use TLSv1.2 and TLSv1.3
$AllProtocols = [System.Net.SecurityProtocolType]'Tls12,Tls13'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols

$errorCount = 0 # counting errors. If this variable is greater than 0, the script should not run
# loading functions
write-host "$(get-date -f  "dd.MM.yyyy HH:mm:ss") include functions"
if (test-path "$($installPath)scripts\functions.global.ps1") {
    write-host "Functions-File exists"
    import-module "$($installPath)scripts\functions.global.ps1" -force
} else {
    write-host "Functions file do not exist. Increasing ErrorCounter." 
    $errorCount++
}

set-location $installPath # setting the location
$machineId = Get-MachineId # generate a unique machineID
write-addylog "All parameter initialized" # write log

# Handling with parameters
if ($debugScript -eq 0) {
    # Load parameter information about this job
    $jsonBody = @{ localCurrentTime = $(get-date -f  "dd.MM.yyyy HH:mm:ss")}
    $body = (ConvertTo-Json -Depth 4 $jsonBody) 
    $resultInitializeInvoke = Invoke-RestMethod -Uri "$addyhostaddress/api/v1/heartbeat-consumer?action=checkforjobs&jobId=$jobId" -Method POST -Body $body -ContentType 'application/json; charset=UTF-8' -Headers @{"Publickey"="$publickey";"Privatekey"="$privatekey";"Machineid" = "$machineId"} # -Headers @{'Authorization'='Basic YWRtaW46YWRtaW4'}
    # take a look in the answer from the addy with $resultInitializeInvoke
    # Example Jobname: $resultInitializeInvoke.jobDataArray.businessAutomationJobsPendingJobname 
    
    # ── Quick reference: Input Parameters (user fills in per job request) ──────
    # $addyPayloadResourceInput = $resultInitializeInvoke.jobDataArray.businessAutomationJobsPendingPayload.payload
    # [string]$aStringParameter = $addyPayloadResourceInput.aStringParameter
    # $aStringParameter = $aStringParameter.trim()

    # ── Quick reference: Resource Parameters (admin sets once, fixed per resource)
    # [string]$ParamAnyString = $resultInitializeInvoke.scriptParameter.anyString
    # $ParamAnyString = $ParamAnyString.trim()
    # [int]$ParamANumber = "$($resultInitializeInvoke.scriptParameter.aNumber)"
}
###################### End header - Start main ############################

# Start: Introducing commands
write-addylog "Start the Script." #-Level "INFO","ERROR", "WARN"
$startOfScript = get-date

write-addylog "Initializing variables"
$errorCount = 0
$error.clear()
# End: Introducing commands


# Start: set a response
$jsonMessageBody = @{  
    message = "working"
    timestamp=$(get-date -f  "dd.MM.yyyy HH:mm:ss")
}
write-addylog "Set a job response. Message to `"working`""
set-JobResponse -jobId $jobId -jsonMessageBody $jsonMessageBody -publickey $publickey -privatekey $privatekey -machineId $machineId
# End: set a response


# ── RESOURCE PARAMETERS ──────────────────────────────────────────────────────
# Set once by the BusinessAdmin, same value for every execution of this resource.
# Typical use: server names, dataset names, flags, API base URLs.
# Defined under Resource > Parameter in the admins buddy UI.
# Start: load resource parameter
write-addylog "Initializing resource parameter"
$addyPayloadResourceParameter = $resultInitializeInvoke.scriptParameter

[string]$temp0resourceparameter = $addyPayloadResourceParameter.temp0resourceparameter
$temp0resourceparameter = $temp0resourceparameter.trim()
write-addylog "[resource parameter] temp0resourceparameter = $temp0resourceparameter"
# End: load resource parameter


# ── INPUT PARAMETERS ─────────────────────────────────────────────────────────
# Filled in by the end user at each job request — different every execution.
# Typical use: target username, department, file content, any job-specific value.
# Defined in the Form Builder when creating the resource in the admins buddy UI.
# Start: load input parameter
write-addylog "Initializing input parameter"
$addyPayloadResourceInput = $resultInitializeInvoke.jobDataArray.businessAutomationJobsPendingPayload.payload

[string]$temp1parameter = $addyPayloadResourceInput.temp1parameter
$temp1parameter = $temp1parameter.trim()
write-addylog "[input parameter] temp1parameter = $temp1parameter"
# End: load input parameter

#
#
#
# Main part
#
#
#


if ($errorCount -eq 0) {
    $responseMessage = "success"
} else {
    $responseMessage = "failed"
}
# Start: set a response at the end
$jsonMessageBody = @{  
    message = $responseMessage
    timestamp=$(get-date -f  "dd.MM.yyyy HH:mm:ss")
    custom=@{
        #value1=$valueExample1 #example to submit different values
        #value2=$valueExample2 #example to submit different values
    }
}
write-addylog "Set a job response. Message to `"working`""
set-JobResponse -jobId $jobId -jsonMessageBody $jsonMessageBody -publickey $publickey -privatekey $privatekey -machineId $machineId
# End: set a response

# Start: cleanup commands
$EndOfScript = get-date
write-addylog "Start of script: $startOfScript"
write-addylog "End of script: $EndOfScript"
$errorCount = 0
$error.clear()
$addyPayloadResourceInput = ""; $addyPayloadResourceParameter = "" # Reset important variables
# End: cleanup commands

###################### End main - Start footer ############################
# setting the state
if ($debugScript -eq 0) {
    write-addylog "update state of this job to done"
    update-modifiedState -jobId $jobId -modifiedState "done" -publickey $publickey -privatekey $privatekey -machineId $machineId
    Start-Sleep 2 
    write-addylog "End of script reached"
    Start-Sleep 2
    exit
}

Next step

Turn this template into a working resource

Once your script is ready, add it as a Resource in your Catalog and start triggering it from admins buddy.