0

I am new to both powershell and sharepoint, and I need to make script to automate the removal and uploading of attachments from outlook to sharepoint. I have easily completed the first part of extracting the attachment, however the uploading to sharepoint has become difficult do to my company's rules. As I understand to use sharepoint cmdlets you need to add the sharepoint snap-in but I am unable to do so because I dont have access to the sharepoint server. Is there anyway to the snapin without being on the server and if not can I upload it another way?

  • Can you use powershell remoting, from your machine to the SharePoint server? e.g. Enter-PSSession -ComputerName – MatthewG Jan 23 '15 at 20:04
  • Ill try that but I dont have much hope. The server is pretty locked down and they probably wont let me. – user3512661 Jan 23 '15 at 20:58

2 Answers2

0

You can't add the SP snap in unless the server is a SP server. Instead, use a webservice/webclient approach to upload the file. Something like this should work depending on your SP version: http://blog.sharepoint-voodoo.net/?p=205

Eric Longstreet
  • 783
  • 1
  • 9
  • 23
0

Accepted answer link is broken.

This script uses PowerShell to upload a file to a document library in SharePoint using purely web service calls so it could be done remotely, also meaning it should work with O365 though I have not tried. These variables are used throughout the script for source file, destination file and authentication. If your workstation is on the same domain as SharePoint, and your logged on user has permissions to the SharePoint site, you can omit $username, $password, and $domain

$LocalPath = "C:\filename.docx"
$spDocLibPath = "http://site.contoso.com/sites/spteam/Shared Documents/"
$username = "someone"
$password = "somepassword"
$domain = "contoso"

$UploadFullPath = $spDocLibPath + $(split-path -leaf $LocalPath)
$WebClient = new-object System.Net.WebClient

if($username -eq "" -or $password -eq "" -or $password -eq "")
{ 
# Use Local Logged on User Credentials
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials
}
else
{
# Alternate Login for specifying credentials
$WebClient.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)
}
$WebClient.UploadFile($UploadFullPath, "PUT", $LocalPath)

https://web.archive.org/web/20160404174527/http://blog.sharepoint-voodoo.net/?p=205

zan_li
  • 73
  • 5
  • Since Powershell v3 (released in 2012) you have the built-in Invoke-WebRequest so using system.net.webclient shouldn't be needed. – bluuf Oct 25 '16 at 05:49