John Pritchard-Williams (JOHNPW_GCS)
Client Support Team Lead
Pegasystems Inc.
JOHNPW_GCS Member since 2009 20 posts
Posted: October 26, 2019
Last activity: October 28, 2019
Posted: 26 Oct 2019 11:28 EDT
Last activity: 28 Oct 2019 11:40 EDT

Powershell script : example

Here's a basic Microsoft Windows Powershell script which shows how easily you can build a set of scripts that communicate directly with the 'Pega API'.

This basic script will create a new Case - populating 'Hard Drive', 'Memory Size' and 'hostname' properties automatically from the Windows host you are one.

First create a CASE in PRPC - in this example I created 'ComputerAudit' and three properties (unfortunately - just realised I spelled 'hard drive' wrong :-)

Now: assuming a couple of other things:

- You have set up Powershell to run on your Windows machine.

(out of scope for this - but check here for instance.

- You have edited the script to match your system coordinates

- You ensure you are connecting with a PRPC Operator who has Pega API access (check access groups).

Here's the basic script:

$hdd_size=Get-Disk|select-object -Property @{n="HDDSize"; expression={[int]($_.Size/1gb)}}|select HDDSize 
$ram_size=(Get-WmiObject win32_physicalmemory|Measure-Object capacity -sum).sum/1gb
$hostname="MyLaptop" # use "$env::COMPUTERNAME" for real hostname

"caseTypeID": "OKE8TW-Gcs-Work-ComputerAudit",
"processID": "pyStartCase",

"content": { "Hostname": "$($hostname)", "HardriveSize": "$($hdd_size.HDDSize)", "MemorySizeGB": "$($ram_size)" }

if ( !( [bool](Get-Variable 'cred' -Scope 'Global' -EA 'Ig') ) ) {
else {
    write-information -MessageData "Using Cached Credentials (unset 'cred' variable to reset)" -InformationAction Continue
$url="{0}/{1}" -F $remote_PRPC_URL, "prweb/api/v1/cases"

$result=Invoke-RestMethod -Method Post -Credential $cred -body $example -Uri $url
write-information -MessageData ("Case Created: {0}" -F $result.ID) -InformationAction Continue
$result | out-gridview

NB: there is no error handling in this script; and there are probably better ways of getting the information (for disks, memory etc) - but it should demonstrate the principle well enough.

Running this should result in an output in a window like this:

As well as text output on the console:

And here's the same case information in a PRPC Portal:

System Administration Developer Knowledge Share