locked
How to import text file data into single item plain text column via powershell RRS feed

  • Question

  • How to import text file data into single item plain text column via powershell?

    I tried below ps which works but strangely it puts system.object in rich text column- plain text.

    $metadata1 = Get-Content C:\ourfolder\metadata.txt
    $title  ="test"
    $site = Get-SPSite http://url
    $web = $site.RootWeb
    $listName = "mylist"
    $list = $web.Lists[$listName]

    Write-Host "test"

      $SPItem = $list.Items | where {$_['Title'] -eq $title }
     $SPItem["Metadata"] = $metadata1 



    $SPItem.Update()

    text file content is like below format

    <List Header=""  XmlVersion="2"  HAlign="Center"  Height="0"  Width="0"  Culture=""  Calendar=""  ToolbarPosition="Top"  RTL="False"  ShowProgressForm="Always"  TabAnimation="FadeIn"  ShowHeader="False"  ShowToolbar="True"  ShowPrint="False"  ShowAlertMe="False"  ShowCancelButton="True"  ShowAttachments="True"  SaveLocalizations="True"  LocalizationsUrl=""  ToolbarImageOnly="False"  ToolbarTooltips="False"  ShowSaveButton="True"  ShowSaveAndExitButton="True"  AllowNew="True"  AllowDelete="True"  RequiredFieldBorderColor="Blue"  HelpPage=""  MarkRequiredFields="False"  AsyncValidation="False"  AsyncLoadCompleted="False"  AsyncSaveCompleted="False"  AsyncDeleteCompleted="False"  FontSize="0"  ShowUserLoginName="False"  FontFamily=""  PrintControls=""  PrintHeaders=""  PrintTemplate=""  PrintCaption="" >
    <Includes>&lt;script type=&quot;text/javascript&quot; src=&quot;/Style Library/ourscript.js&quot;&gt;&lt;/script&gt;




    &lt;script&gt;
    function setupDrop(ID, form, returnMapping){
            var forMapping = 


    MCTS Sharepoint 2010, MCAD dotnet, MCPDEA, SharePoint Lead

    Thursday, December 8, 2016 9:24 PM

Answers

  • You need to convert the output to string when using Get-Context. Use the following

    Get-Content "C:\ourfolder\metadata.txt" | Out-String


    Cheers,
    My Blog

    Friday, December 9, 2016 5:35 AM

All replies

  • You need to convert the output to string when using Get-Context. Use the following

    Get-Content "C:\ourfolder\metadata.txt" | Out-String


    Cheers,
    My Blog

    Friday, December 9, 2016 5:35 AM
  • Hi Amit Lohogaonkar sharepointer,

    Per my test in my SharePoint 2013 environment, if I add the content in your post in the metadata.txt, i get the “system.object” in the rich text column-plain text. If I just add some characters in the metadata.txt, it just displays the same characters in the rich text column-plain text. Could you please provide complete content which will be added to the rich text column by PowerShell command.

    Then I split the content in your post. If I just add the content below in metadata.text, it will copy the same content from metadata.txt to the rich text column.

    <List Header=""  XmlVersion="2"  HAlign="Center"  Height="0"  Width="0"  Culture=""  Calendar=""  ToolbarPosition="Top"  RTL="False"  ShowProgressForm="Always"  TabAnimation="FadeIn"  ShowHeader="False"  ShowToolbar="True"  ShowPrint="False"  ShowAlertMe="False"  ShowCancelButton="True"  ShowAttachments="True"  SaveLocalizations="True"  LocalizationsUrl=""  ToolbarImageOnly="False"  ToolbarTooltips="False"  ShowSaveButton="True"  ShowSaveAndExitButton="True"  AllowNew="True"  AllowDelete="True"  RequiredFieldBorderColor="Blue"  HelpPage=""  MarkRequiredFields="False"  AsyncValidation="False"  AsyncLoadCompleted="False"  AsyncSaveCompleted="False"  AsyncDeleteCompleted="False"  FontSize="0"  ShowUserLoginName="False"  FontFamily=""  PrintControls=""  PrintHeaders=""  PrintTemplate=""  PrintCaption="" >

    Then I just add the JavaScript code below, it also will copy the same content from metadata.txt to the rich text column.

     <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function () {

    alert("aa");

    });

    </script>

    Then I add the content below in the metadata.txt, it also will copy the same content from metadata.txt to the rich text column.

    <List Header=""  XmlVersion="2"  HAlign="Center"  Height="0"  Width="0"  Culture=""  Calendar=""  ToolbarPosition="Top"  RTL="False"  ShowProgressForm="Always"  TabAnimation="FadeIn"  ShowHeader="False"  ShowToolbar="True"  ShowPrint="False"  ShowAlertMe="False"  ShowCancelButton="True"  ShowAttachments="True"  SaveLocalizations="True"  LocalizationsUrl=""  ToolbarImageOnly="False"  ToolbarTooltips="False"  ShowSaveButton="True"  ShowSaveAndExitButton="True"  AllowNew="True"  AllowDelete="True"  RequiredFieldBorderColor="Blue"  HelpPage=""  MarkRequiredFields="False"  AsyncValidation="False"  AsyncLoadCompleted="False"  AsyncSaveCompleted="False"  AsyncDeleteCompleted="False"  FontSize="0"  ShowUserLoginName="False"  FontFamily=""  PrintControls=""  PrintHeaders=""  PrintTemplate=""  PrintCaption="" >

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function () {

    alert("aa");

    });

    </script>

    After all, you could check if there is error in the JavaScript code in your metadata.txt. And check if it can work when you add the content to rich text column by editing the item.

    Best regards,

    Sara Fan


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, December 9, 2016 7:38 AM
  • Prasath, thank you it worked for me!

    Get-Content "C:\ourfolder\metadata.txt" | Out-String


    MCTS Sharepoint 2010, MCAD dotnet, MCPDEA, SharePoint Lead

    Thursday, December 15, 2016 7:58 PM