Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

19 thoughts on “How to Upload File to SharePoint Library using PowerShell?

  • June 19, 2020 at 4:06 PM

    Do you have a SharePoint Online (O365) version for these scripts (especially the ‘with metadata’ version’)?

    Reply
  • October 30, 2015 at 7:24 AM

    Hello,

    Is it possible to run the above script where SharePoint is not installed?

    Actually i am trying to upload documents to sharepoint site by running a script in non sharepoint server but its failing with an error.

    Could you please help me in achieving this.

    Thanks in Advance.

    Reply
  • September 3, 2015 at 9:36 AM

    can it taake metadata from excel ?

    Reply
  • November 6, 2013 at 2:40 PM

    Will this work if I want to copy a bunch of files to a sharepoint folder inside a library ?

    Also getting this error

    Exception getting “Item”: “urlOfFile
    Parameter name: Specified value is not supported for the urlOfFile parameter.”
    At line:33 char:4
    + if($Files.Item($DocLibName +”/” + $FileName))
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], GetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenGetting

    Reply
  • February 19, 2013 at 7:20 PM

    Hi Sal, is it possible to use this to update an item that is in a Managed Metadata column? I am able to get do a text entry just fine thanks to your script, but it will not work on Managed Metadata in a Term Store.

    Reply
  • November 27, 2012 at 2:12 PM

    That’s some prompt answering, Sal! Tried it al, works a charm. Thanks, your help is greatly appreciated! Regards, Jan

    Reply
  • November 26, 2012 at 6:29 PM

    Oops, I forgot another question: is it possible to set the Content Type used when uploading?

    Reply
    • November 27, 2012 at 9:29 AM

      Yes, You can set the Content Type for your items while uploading. Here is how:

      #Get the Content Type
      $ctype = $web.ContentTypes[“YOUR-Content-Type”];
      #Set Content Type Property
      $Metadata.add(“ContentTypeId”, $ctype.Id);

      Regards,
      Sal

      Reply
  • November 26, 2012 at 6:28 PM

    Hi Salaudeen, i tried to update the “Title” column of a document item with both your methods, but without any success, unfortunately. Am I doing something wrong?

    First method: $Metadata.add(“Title”, “SomeValue”) – Result: Title stays empty. Other metadata works fine!
    Second method: $UploadedFile.Item[“Title”]=”SomeValue” – Result: error message about Null valued array.

    Thanks for a great and helpful article, hope you can help a little bit more. Thanks in advance, and regards from the Netherlands!

    Reply
    • November 27, 2012 at 11:17 AM

      Hi Jan,

      Just verified the second method, Works as expected:

      $UploadedFile=$Files.Add($DocLibName +”/” + $FileName,$File.OpenRead(), $true)
      $UploadedFile.Item[“Title”]= “Title Value Goes here”
      $UploadedFile.Item.Update()

      Reply
  • November 26, 2012 at 6:17 PM

    Nice article Salaudeen, it really helped me a lot! However, I’m experiencing some problems when trying to update the “Title” column of a document. I just added the line:
    $Metadata.add(“Title”, “SomeValue”)

    but nothing happened. Tried the second method as well:
    $UploadedFile.Item[“Title”]=”SomeValue”

    but again no success. Any idea what I might be doing wrong? Thanks in advance!
    Regards, Jan

    Reply
    • November 27, 2012 at 11:15 AM

      Hi Jan,

      For Title Field, Use: “vti_title” when you use Hash-table.

      $Metadata.add(“vti_title”, “Your Title Value”)

      Reply
  • November 19, 2012 at 3:57 AM

    What if the file has a metadata associated with it ? For e.g. if it has a “Month” field that need to be filled up while uploading the document ?

    Reply
    • November 19, 2012 at 7:58 AM

      Hi KR,

      Updated the post with setting Metadata values in PowerShell.

      Hope it helps.

      Reply

Leave a Reply