Use Powershell to download attached excel file from Servicenow ticket Use Powershell to download attached excel file from Servicenow ticket powershell powershell

Use Powershell to download attached excel file from Servicenow ticket


Yes, you need credentials but don't hard code them like that. Instead you can use built-in method Get-Credential that will securely collect your username and password. The user will have to enter their own ServiceNow credentials each time this is run.

My version only has one thing you need to configure, the $SubDomain variable which is specific to your tenant.

$SubDomain = "YourServiceNowSubdomaingoeshere" # Configure this per tenant$Credential = Get-CredentialIf(!$Credential){    # User Cancelled    exit 1}$IncidentNumber = Read-Host -Prompt 'Enter Incident Request #'$Uri = "https://$SubDomain.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 $Credentialif($IncidentResult.result.sys_id -ne $null) {    $IncidentAttachments = Invoke-RestMethod -Uri "https://$SubDomain.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!"}


Yes you need credentials.

Your URI is the URL of your servicenow instance. Change the dev42835 portion to match. If you're unsure of your instance, contact servicenow support.https://dev42835.service-now.com

If you use the REST API explorer, you can view API endpoints and versions which will help with forming your requests. You do need to have the rest_api_explorer role to access the REST API Explorer. If you do not have this role, contact your service-now admin requesting it.

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/task/t_GetStartedAccessExplorer.html