I'm currently working on a powershell script that should be able to download an attached excel file from a service now ticket, before I explain more please see the basic flow of the automation below.
- The user will be asked to enter the ticket number.
- The system will then find that incident ticket to accurately get the excel file needed(I saw online that I need to use sys_id).
- It will then be downloaded to a specific path on the user's machine. ex: "C:\downloads\Demo\".
Following all this, I found a sample script online that I'm trying to configure to match my needs; however, I'm not sure where to get the values on that sample script. You can check the bullets below the script for the questions I have in mind.
$IncidentNumber = Read-Host -Prompt 'Enter Incident Request #'
#$admin = "admin"
#$password = "admin" | ConvertTo-SecureString -AsPlainText -Force
#$Credential = New-Object pscredential -ArgumentList ($admin,$password)
$Uri = "https://dev42835.service-now.com/api/now/table/incident?sysparm_query=number=$($IncidentNumber)&sysparm_fields=sys_id&sysparm_limit=1"
$IncidentResult = Invoke-RestMethod -Uri $Uri #-Method Get -Credential $Credential
if($IncidentResult.result.sys_id -ne $null) {
$IncidentAttachments = Invoke-RestMethod -Uri "https://dev42835.service-now.com/api/now/attachment?sysparm_query=table_sys_id=$($IncidentResult.result.sys_id)" #-Method Get -Credential $Credential
$IncidentAttachments.result | Select file_name , download_link
}
else{
"Incident Not Found!"
}
- Do I really need the credentials to run the script? If yes, is there a way to remove the need of the credentials?
- Where can I get the URL that is assigned to the $URI variable?
I'm new to powershell automation so I would appreciate it if you can recommend better approach if there are any.