<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Powershell Script to Upload file to table in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860689#M517615</link>
    <description>&lt;P&gt;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!&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jul 2020 15:20:30 GMT</pubDate>
    <dc:creator>Tim Darrach1</dc:creator>
    <dc:date>2020-07-09T15:20:30Z</dc:date>
    <item>
      <title>Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860683#M517609</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;We have been looking for a solution for automating an upload from an Excel doc to a table as if just went to the table and did a right click &amp;gt; Import. We had tried setting it up originally as a scheduled import and setting up the Data Source as Type: File, Format: Excel, File Retrieval Method: File and couldn't get that to work. Tried reading some online sources and they made it seem like this import option doesn't actually work so we moved on to trying it with Powershell instead. If someone knows how to make that work instead this could save us some trouble.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So we moved onto attempting an upload through a Powershell script. I've got it to the point where it will run and connect to our instance but in our Import Log we see the error message&lt;/P&gt;
&lt;P&gt;"Attachment could not be successfully extracted." from Source: ImportProcessor.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have a few questions about making this work as a Powershell script. Apologies if these seem amateur, I'm just learning this from scratch as I go.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have used this as our URL using the import set table "u_imp_tmpl_u_luis_custom_test". Should the import set table be used or should it be the actual table we mean to have the data sent to?&lt;/P&gt;
&lt;P&gt;https://xxxxxxxxx.service-now.com/sys_import.do?sysparm_import_set_tablename=u_imp_tmpl_u_luis_custom_test&amp;amp;sysparm_transform_after_load=true&lt;/P&gt;
&lt;P&gt;How does ServiceNow expect the body to look? Can I simply import it as an .xlsx? Would it have to be converted to .csv or .json first? Would the body of the upload have to be converted to into some format SNOW would recognize?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To insert new records on a table is -method POST or PUT recommended?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 13:49:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860683#M517609</guid>
      <dc:creator>Tim Darrach1</dc:creator>
      <dc:date>2020-07-08T13:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860684#M517610</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;POST method is used to create record into import set table.&lt;BR /&gt;&lt;BR /&gt;you are using the right import set API. XLSX is proper format which you can use.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;But the only thing is are you attaching this file to a data source and then the data source is running?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are fetching an csv file from MID Server which automatically goes into import set table. But we are fetching it not like your case. You want to push it.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Ashutosh&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 15:31:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860684#M517610</guid>
      <dc:creator>Ashutosh Munot1</dc:creator>
      <dc:date>2020-07-08T15:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860685#M517611</link>
      <description>&lt;P&gt;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?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 19:48:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860685#M517611</guid>
      <dc:creator>Tim Darrach1</dc:creator>
      <dc:date>2020-07-08T19:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860686#M517612</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;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.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thakns,&lt;BR /&gt;Ashutosh&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2020 09:26:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860686#M517612</guid>
      <dc:creator>Ashutosh Munot1</dc:creator>
      <dc:date>2020-07-09T09:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860687#M517613</link>
      <description>&lt;P&gt;Sorry I'm confused. I thought that we would use either the Import module with a data source or Powershell. Just one or other other. Do you mean to set up the Data Source with File Retrieval Method set to Attachment and then use Powershell to attach the file to the Data Source record?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2020 12:53:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860687#M517613</guid>
      <dc:creator>Tim Darrach1</dc:creator>
      <dc:date>2020-07-09T12:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860688#M517614</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;Check those links might this helps you&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.servicenow.com/community?id=community_article&amp;amp;sys_id=df3caa61dbd0dbc01dcaf3231f9619aa" rel="nofollow"&gt;https://community.servicenow.com/community?id=community_article&amp;amp;sys_id=df3caa61dbd0dbc01dcaf3231f9619aa&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=6513cfa1dbd8dbc01dcaf3231f9619f1" rel="nofollow"&gt;https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=6513cfa1dbd8dbc01dcaf3231f9619f1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please mark correct or helpful.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2020 12:59:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860688#M517614</guid>
      <dc:creator>Swapnil Soni1</dc:creator>
      <dc:date>2020-07-09T12:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860689#M517615</link>
      <description>&lt;P&gt;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!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2020 15:20:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860689#M517615</guid>
      <dc:creator>Tim Darrach1</dc:creator>
      <dc:date>2020-07-09T15:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860690#M517616</link>
      <description>&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 00:26:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860690#M517616</guid>
      <dc:creator>KLee19</dc:creator>
      <dc:date>2020-08-06T00:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860691#M517617</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;# 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&amp;amp;table_sys_id=e977e602dbc91850dffc9a26db9619b4&amp;amp;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

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 13:43:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/1860691#M517617</guid>
      <dc:creator>Tim Darrach1</dc:creator>
      <dc:date>2020-08-06T13:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Script to Upload file to table</title>
      <link>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/2439007#M950257</link>
      <description>&lt;P&gt;HI Tim,&lt;/P&gt;&lt;P&gt;I am using the below script its just my requirement is to read data from CSV. But get syntax error while running action in flow designer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Eg. User name="admin", Password="admin" for this code sample.&lt;BR /&gt;$user = "Integration"&lt;BR /&gt;$pass = "Micromax123#"&lt;/P&gt;&lt;P&gt;# Build auth header&lt;BR /&gt;$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))&lt;/P&gt;&lt;P&gt;# Set proper headers&lt;BR /&gt;$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"&lt;BR /&gt;$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))&lt;BR /&gt;#$headers.Add('Accept','application/json')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Specify endpoint uri - this is the Data Source record for the import&lt;BR /&gt;$uri = "&lt;A href="https://xxxxx.service-now.com/api/now/attachment/file?table_name=sys_data_source&amp;amp;table_sys_id=532273991bd46dd46440eca7b04bcbe4&amp;amp;file_name=splunk_data_against_AD.csv" target="_blank"&gt;https://xxxxx.service-now.com/api/now/attachment/file?table_name=sys_data_source&amp;amp;table_sys_id=532273991bd46dd46440eca7b04bcbe4&amp;amp;file_name=splunk_data_against_AD.csv&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Specify HTTP method&lt;BR /&gt;$method = "post"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#Get the attachment file to send to SNOW to be imported&lt;BR /&gt;$filePath = "E:\xxxxx\splunk_data_against_AD.csv"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$contentType = "multipart/form-data"&lt;BR /&gt;#contentType = "application/text/csv"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Send HTTP request&lt;BR /&gt;$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -ContentType $contentType -InFile $filePath&lt;/P&gt;&lt;P&gt;# Print response&lt;BR /&gt;$response.RawContent&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appericate early response and help&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 16:16:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/powershell-script-to-upload-file-to-table/m-p/2439007#M950257</guid>
      <dc:creator>shilpi sharma</dc:creator>
      <dc:date>2023-01-10T16:16:26Z</dc:date>
    </item>
  </channel>
</rss>

