Zach Rosenfield has a nice post on calling WebServices from PowerShell. The steps are pretty simple: generate a proxy cs file, compile it into a DLL and then load that DLL up into Powershell AppDomain.
Well I've been doing some work with quite a few of the WebServices and I wanted to compile all the proxys into a single DLL.
Use Zach's post to setup the PowerShell environment variables needed to call the Visual Studio SDK utilities wsdl.exe and csc.exe
Heres the script to compile all the available SharePoint Webservice's into one DLL.
It simply enumerates all the ASMX files in the ISAPI directory and passes each item in that list to WSDL.exe which generates the proxy cs files.
You need to change the URL in this script to point to a valid SharePoint site and make sure there are no other .cs files in the directory before running this script.
$asmxlist= dir "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI" *.asmx | select name $asmxlist | foreach-object { write-host "Generating SharePoint Proxy Library for $($_.name)" -foregroundcolor green $outputfilename="FlexnetConsult.SharePoint.$($_.name).cs" $namespace=[IO.Path]::GetFileNameWithoutExtension($_.name) wsdl "http://portal.contoso.com/matters/sites/_vti_bin/$($_.name)" /o:$outputfilename /namespace:$namespace } write-host "Compiling SharePoint Proxy Library" -foregroundcolor green csc /t:library /out:FlexnetConsult.SharePoint.WebServices.dll *.cs
So the output should be something like this
Now three of the WebServices generate an error SlideShow.asmx. FormserverProxy.asmx and contentareatoolboxservice.asmx but as I'm unlikely to use them I'm not going to worry about those.
So now we have a DLL called FlexnetConsult.SharePoint.WebServices.dll in our directory that we can use to call the (almost) any SharePoint Web Service.
I've attached the compiled dll and script.
In my next post I'll use the DLL to do something I've wanted to do for ages and that's list, add and delete Web Parts on a page using PowerShell.
Now your probably shouting, hey why not just call the object model and GetLimitedWebPartManager, yep but that doesn't work as without a web.config and possibly a HttpContext all you get back are Error WebParts as the WebPart safecontrollist cannot be accessed.
GenerateSharePointProxyLibrary.ps1
FlexnetConsult.SharePoint.WebServices.dll
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Colin Byrne
E-mail