I wrote a PowerShell .ps1 for this purpose via FrontDoor. You must authenticate via API calls. For my script I am using a Windows 2012 R2 server with windows task scheduler. Couple things to keep in mind.
1. You can setup a secured API key if your environment utilizes SSO, this is done through the user account management in Frontdoor
2. I masked the API key on our server and encrypted it due to security reasons
3. This can be used to run against Active Directory to check for user account status (what I use it for)
4. I would suggest coping and pasting the below into PowerShell ISE for a better view of the code
5. The first portion of the code can be used over again for authenticating via API key in R12 and pass the token in the -header switch for future API calls
This script is pretty long and if you have any specific questions please let me know!
#############################################################################################################
#Script to use API calls for Apptio FrontDoor applications #
#Script written by Robert Schneider December 15th 2017 currently using API Key #
#############################################################################################################
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent #set the current path of the script Get-location |select path
$secretkey = "$PSScriptRoot\secretkey.pwd" #setting path of secretkey file
$publickey = "$PSScriptRoot\publickey.pwd" #setting path of publickey file
if (((Test-Path $secretkey) -eq $false) -or (Test-Path $publickey) -eq $false){ #testing path for public / secret key file
#below is a custom input form for the public/private key pair
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Public/Private Key Entry"
$objForm.Size = New-Object System.Drawing.Size(300,250)
$objForm.StartPosition = "CenterScreen"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,180)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.windows.forms.dialogresult]::OK
$objForm.AcceptButton= $OKButton
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,180)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.DialogResult = [System.windows.forms.dialogresult]::Cancel
$objForm.AcceptButton= $CancelButton
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "PLEASE ENTER PUBLIC KEY:"
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,100)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "PLEASE ENTER PRIVATE KEY:"
$objForm.Controls.Add($objLabel)
$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,120)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)
$objForm.topmost = $true
$result = $objform.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x= $objTextBox.Text
$y= $objTextBox2.Text
}
if ($result -eq [System.Windows.Forms.DialogResult]::Cancel)
{
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("YOU HAVE CANCELLED YOUR INPUT, PLEASE TRY AGAIN AND ENSURE YOU'RE SELECTING OK.",0,"Error")|Out-Null
exit}
#end of custom input form for the public/private key pair
$x|ConvertTo-SecureString -AsPlainText -Force|convertFrom-SecureString > $publickey #exporting and encrypting publickey
$y|ConvertTo-SecureString -AsPlainText -Force|convertFrom-SecureString > $secretkey #exporting and encrypting secretkey
}
$secretkeyplain = Get-Content -path $secretkey #pulling encrypted secretkey
$publickeyplain = Get-Content -path $publickey #pulling encrypted publickey
$PlainTextSecret= [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR( (ConvertTo-SecureString $secretkeyplain) )) #unencrypting secretkey
$PlainTextPublic= [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR( (ConvertTo-SecureString $publickeyplain) ))#unencrypting publickey
$string =@{keySecret=$PlainTextSecret;keyAccess=$PlainTextPublic} |convertto-json -compress #creating hash-table to pass public/private key pair to apptio
$header = Invoke-WebRequest -Method Post -Uri 'https://frontdoor.apptio.com/service/apikeylogin' -ContentType "application/json" -Body $string |Select -ExpandProperty headers #retrieving key header for opentoken
$opentoken=@{"apptio-opentoken"=$header."apptio-opentoken"} #must be in a table format for passing credentials must pass in -header parameter in invoke-restmethod (get) and Invoke-WebRequest (curl/post)
#############################################################################################################
#Remaining scripts are API calls using opentoken from authentication above must pass $opentoken in -header #
#############################################################################################################
#Be sure to replace {yourdomainhere} below with your domain**
$users=Invoke-RestMethod -Method Get -Uri 'https://frontdoor.apptio.com/api/v2/users/search?domainName={yourdomainhere}&hideInactive=false&start=0&pageSize=100&sortBy=login' -headers $opentoken #getting user list and passing open token
$login= @($users.data.objects.login) #setting objects to string
$date=get-date -Format MMddyymmss #getting unique date time and second count for file export
#foreach loop to check email of user accounts in Apptio against active directory and return active vs non-active users *excludes any logins with svc in the name
foreach ($email in $login){
$usercheck = get-aduser -Filter {mail -eq $email} -Properties mail |select mail
if ([string]::IsNullOrEmpty($usercheck) -and $email -notmatch "svc_" -and $email -notmatch "service"){$email >>nonactive_users_$date.csv}
elseif (-not [string]::IsNullOrEmpty($usercheck)){$email >>active_users_$date.csv}
}