Maybe I didn't explain correctly. We attempted doing this using a scheduled import from a data source at first but when we couldn't find a way to do that by just selecting an Excel file we skipped past that altogether and moved onto trying to do it entirely from a Powershell script. Is it possible to set up an import Data Source to point to an Excel file and upload that way? 

Hi,

You can create a data source for excel. Then you can import the excel file from PowerShell and then attach that file to data source and trigger the data source using script. This will help you.


Thakns,
Ashutosh

Since we already had the scheduled import/data source structure setup I took another look at using Powershell to upload the Excel file to the data source as an attachment and that worked. So we're all set. We'll just run the import from the data source attachment. Thanks for the help!

Hi Tim, I am trying to do something similar but I am posting to the import set table. I get the attachment could not be extracted error. Any suggestions?

I think we ran into that issue at one point. The only way I could find to work was uploading the file as an attachment to the Data Source record and then setting the Scheduled Import to import from attachment directly. Here is what we used, however this was for an Excel file, not a CSV so it might take some adjustment.

# Eg. User name="admin", Password="admin" for this code sample.
$user = ""
$pass = ""

# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))

# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
#$headers.Add('Accept','application/json')



# Specify endpoint uri - this is the Data Source record for the import
$uri = "https://xxxxxxx.service-now.com/api/now/attachment/file?table_name=sys_data_source&table_sys_id=e977e602dbc91850dffc9a26db9619b4&file_name=u_luis_custom_test_input.xlsx"


# Specify HTTP method
$method = "post"


#Get the attachment file to send to SNOW to be imported
$filePath = "C:\Users\xxxxxxx\test_input.xlsx"



$contentType = "multipart/form-data"
#contentType = "application/vnd.ms-excel"


[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


# Send HTTP request
$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -ContentType $contentType -InFile $filePath

# Print response
$response.RawContent