1

I'm trying to upload some files to SharePoint 2013 document library using PowerShell and SharePoint 2013 web services (/_vti_bin/copy.asmx). There is some examples how to use copy.asmx web service on C# like this but I want to do this with powershell. How can I do this? How can I use /_vti_bin/copy.asmx web services from PowerShell?

I will upload files to a SharePoint farm which is not in our domain so I need to set username and password.

Thanks in advance.

Update:

I've solved my problem to upload file with following code; but I couldn't set the meta data fields of document.

$URI = "http://www.example.com/sites/dev/_vti_bin/copy.asmx?WSDL" $securePasssword = ConvertTo-SecureString "password" -AsPlainText -Force $credentials = New-Object System.Management.Automation.PSCredential ("xyz\username", $securePasssword) $proxy = New-WebServiceProxy -Uri $URI -Namespace ILS -Credential $credentials $data = [IO.File]::ReadAllBytes("C:\Users\user\Desktop\TestDoc.pdf") $fields =@() $field = New-Object -TypeName ILS.FieldInformation $field.DisplayName="Disp" $field.InternalName="Title" $field.Value="t.pdf" $fields+=$field $date1 = Get-Date -Format "yyyyMMddHHmmss" $results = $null $proxy.CopyIntoItems(" ","http://www.example.com/sites/Dev/TestLib/TestDoc_$date1.pdf", [ILS.FieldInformation]$fields,$data,[ref] $results) 

It gives me following error

enter image description here

    2 Answers 2

    0

    Here’s a quick example of how to upload a document on a SharePoint server using the SharePoint PowerShell module which uses the SharePoint Object Model.

    # Set the variables $WebURL = “http://portal.contoso.com/sites/stuff” $DocLibName = “Docs” $FilePath = “C:\Docs\stuff\Secret Sauce.docx” # Get a variable that points to the folder $Web = Get-SPWeb $WebURL $List = $Web.GetFolder($DocLibName) $Files = $List.Files # Get just the name of the file from the whole path $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) # Load the file into a variable $File= Get-ChildItem $FilePath # Upload it to SharePoint $Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) $web.Dispose() 
    1
    • Thank you for your answer; but I need to use web services. The farm which the document will be uploaded to is in another domain.
      – newbie
      CommentedJan 31, 2017 at 13:51
    0

    Here you have one example From Todd Klindt blog

    # Set the variables $destination = "http://portal.contoso.com/sites/stuff/Docs” $File = get-childitem “C:\Docs\stuff\Secret Sauce.docx” # Since we’re doing this remotely, we need to authenticate $securePasssword = ConvertTo-SecureString "pass@word1" -AsPlainText -Force $credentials = New-Object System.Management.Automation.PSCredential ("contoso\johnsmith", $securePasssword) # Upload the file $webclient = New-Object System.Net.WebClient $webclient.Credentials = $credentials $webclient.UploadFile($destination + "/" + $File.Name, "PUT", $File.FullName) 
    2
    • Thank you @Marek, but this did not work for me :(
      – newbie
      CommentedFeb 1, 2017 at 6:41
    • Do you receive any error? exception?CommentedFeb 1, 2017 at 17:09

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.