Connect Sharepoint remotely using Powershell

Usually working with Sharepoint list using Powershell (PWS) means you need to run a PWS script locally on the given sharepoint server or at least you have to install a “little”, playground Sharepoint (foundation or services) to be able to import the sharepoint dll at the begining of your script.

i’m just writing about this line: [System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

Ohh yeah. But as a little child i’m frustrated: I don’t want to install sharepoint just to import such a dll… i would like to do something else…
And here we go. Not so simple but i think it worths doing. Every cookbook starts with the sentence: have a saucepan.

PreDos – Create your own DLL

you need to do this just one time, this DLL can be used to connect to all other default sharepoint list using webservice in the future. (Or you can download a created Lists.dll file from HERE ~70KB if you are a bit lazy)

Please install Visual Studio. (in this post i installed VS8)

We need to install the .Net SDK to a developer machine from the link: 350MB

Then we need to set the environment parameters to have a well-working translator-environment (for wsdl.exe and csc.exe). I just copied the rows below and had three errors… i had no time to debug. The solution worked in this way also.

$env:VSINSTALLDIR="C:\Program Files\Microsoft Visual Studio 8"
$env:VCINSTALLDIR="C:\Program Files\Microsoft Visual Studio 8\VC"
$env:FrameworkDir=$(split-path $FrameworkPath -Parent)
$env:FrameworkVersion=$(split-path $FrameworkPath -Leaf)
$env:PATH="$env:VSINSTALLDIR\Common7\IDE;$env:VCINSTALLDIR\BIN;$env:VSINSTALLDIR\Common7\Tools;$env:VSINSTALLDIR\Common7\Tools\bin;$env:VCINSTALLDIR\PlatformSDK\bin; $env:FrameworkSDKDir\bin;$env:FrameworkDir\$env:FrameworkVersion;$env:VCINSTALLDIR\VCPackages;$env:PATH"
$env:LIB="$env:VCINSTALLDIR\ATLMFC\LIB; $env:VCINSTALLDIR\LIB;$env:VCINSTALLDIR\PlatformSDK\lib;$env:FrameworkSDKDir\lib;$env:LIB"

*IMPORTANT: on a 64 bit machine you need to put the first variable ($env:VSINSTALLDIR) to be “C:\Program Files (x86)\Microsoft Visual Studio 8”

Let’s generate the source for the Classes

The webservice is a cool thing as it tells everything about itself (attributes and methods). We need just to create the .Net sourcecode of it. We can use the WSDL.exe application for that. 

wsdl http://intranet/_vti_bin/Lists.asmx

Having run this command we’ll have such a code which can use the services connected to this URL by default. Now you have a CS file with the line in it:

public Lists() {
this.url = "http://intranet/_vti_bin/Lists.asmx;

Let’s Render the code

Running the next command we have the DLL itself (reference:

csc /t:library Lists.cs

And we can use our fresh new-brabded DLL at every machine (Windows ūüôā )

Use your own DLL at your PWS script

You need just to load your brand-new. dll in a normal way as you did with Sharepoint dll till now. (The DLL can be downloaded from HERE ~70KB also)


And here we are, we can create our new List object ūüôā hurray

$list = New-Object Lists

If you need other credential:

$list.Credentials = (Get-Credential).GetNetworkCredential())

So we can use methods as we have an instance –

$docs = $list.GetList(‚ÄúShared Documents‚ÄĚ)
$docs | Get-Member

# If you downloaded the Lists.dll you should change the URL property for the instance to your one.
$list.url = "http://yourintranet/listname/_vti_bin/lists.asmx"

PS d:\>$list
SoapVersion                          : Default
AllowAutoRedirect                    : False
CookieContainer                      :
ClientCertificates                   : {}
EnableDecompression                  : False
UserAgent                            : Mozilla/4.0 (compatible; MSIE 6.0; MS We
 b Services Client Protocol 2.0.50727.495
Proxy                                :
UnsafeAuthenticatedConnectionSharing : False
Credentials                          :
UseDefaultCredentials                : False
ConnectionGroupName                  :
PreAuthenticate                      : False
Url                                  : http://wwwin/minosegugy/_vti_bin/Lists.a
RequestEncoding                      :
Timeout                              : 100000
Site                                 :
Container                            :


I know that we can use remote pws scripting in Powershell v2 and other webproxy possibilities.. but somehow this process is a bit closer to me.. i don’t know why ūüėõ

anyway no need to turn on the remote session at the destination (Sharepoint) server

In the near future i would like to post an article on how to use this method to manipulate rows in sharepoint list.

Reference – Zach Rosenfield

And more

If you need more webservice just use some below:

Administration Service             :           http://<server-url:port-number>/_vti_adm/admin.asmx
Alerts Service                           :           http://<server-url>/_vti_bin/alerts.asmx
Document Workspace Service :           http://<server-url>/_vti_bin/dws.asmx
Forms Service                          :           http://<server-url>/_vti_bin
Imaging Service                       :           http://<server-url>/_vti_bin
List Data Retrieval Service        :           http://<server-url>/_vti_bin/dspsts.asmx
Lists Service                            :           http://<server-url>/_vti_bin/lists.asmx
Meetings Service                     :           http://<server-url>/_vti_bin/meetings.asmx
Permissions Service                 :           http://<server-url>/_vti_bin/permissions.asmx
Site Data Service                      :           http://<server-url>/_vti_bin/sitedata.asmx
Site Service                              :           http://<server-url>/_vti_bin/sites.asmx
Users and Groups Service        :           http://<server-url>/_vti_bin/usergroup.asmx
Versions Service                      :           http://<server-url>/_vti_bin/versions.asmx
Views Service                           :           http://<server-url>/_vti_bin/views.asmx
Web Part Pages Service           :           http://<server-url>/_vti_bin/webpartpages.asmx
Webs Service                           :           http://<server-url>/_vti_bin/webs.asmx
Area Service                             :           http://<server-url>/_vti_bin/areaservice.asmx
Query Service                          :           http://<server-url>/_vti_bin/search.asmx
User Profile Service                  :           http://<server-url>/_vti_bin/userprofileservice.asmx
SPS Crawl Service                     :           http://<server-url>/_vti_bin/spscrawl.asmx
Outlook Adapter Service          :           http://<server-url>/_vti_bin/outlookadapter.asmx



3 thoughts on “Connect Sharepoint remotely using Powershell”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s