Home Page Link
  Skip Navigation Links
ZA SharePointers
Information Worker > Blogs > ZA SharePointers > Categories
Scripting SharePoint without PowerShell

In my previous blog I wrote on how to use PowerShell to do various things in SharePoint.  Well today I had to a lot of information on site collections in a farm.  Things like list all the site collections in all web applications and show the owner, owner email, URL, name, quota, actual size etc.  Just a lot of useful information about the site collections in the farm.

  I can get most of the information from the central admin, but I would need to copy and paste in a lot of different places and it would take a looooong time if there is a lot of web applications and site collections.

I could also use stsadm with operations like enumzoneurls and enumsites.  That would simplify the task, but it would still require manual effort and it would not be very repeatable if I had to do it on regular intervals.

I thought about PowerShell as well, but PowerShell was not installed in the environment and I could not install it due to various operational reasons. 

Then I thought about .Net Framework.  It was installed on the server (requirement for SharePoint), and it comes with a C# compiler.  I could use my trusty old Visual N++ development environment that comes with every install of windows.  (That is Notepad for those who don't know) And then compile it with csc and pull the reports that I want to.

I am not a real developer, so I struggled a bit to write the script and to compile it.  Here is my effort for the script and how to compile it if you need to do something like this quickly and don't have time to play around.

C# Script:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

class MainApp {
   public static void Main() {
      Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}","AppName","AppUrl","HostName","SiteTitle","SitUrl","Size","Quota","Owner","EMail","Template");
      SPFarm farm = SPFarm.Local;
      SPWebService service = farm.Services.GetValue<SPWebService>("");
      foreach (SPWebApplication webApp in service.WebApplications)
           {
               foreach (SPSite site in webApp.Sites )
                  {
                      Console.Write("{0}\t", webApp.DisplayName);
                      Console.Write("{0}\t", webApp.AlternateUrls[0].Uri);
                      Console.Write("{0}\t", site.HostName);
                      Console.Write("{0}\t", site.RootWeb.Title);
                      Console.Write("{0}\t", site.Url);
                      Console.Write("{0}\t", site.Usage.Storage);
                      Console.Write("{0}\t", site.Quota.StorageMaximumLevel);
                      Console.Write("{0}\t", site.Owner.LoginName);
                      Console.Write("{0}\t", site.Owner.Email);
                      Console.WriteLine("{0}#{1}", site.RootWeb.WebTemplate,site.RootWeb.WebTemplateId);
                  }
           }

   }
}

 

And then more important the command line to compile:

csc.exe /debug+ /out:.\get-hmc-wss-info.exe get-hmc-wss-info.cs /reference:"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI\Microsoft.SharePoint.dll"

 

The part I struggled with was setting the reference to the SharePoint assembly.  The command line above shows how to add the reference for the using clause in the code to work.

Lekker Scripting


RSS Feed RSS 2.0 Feed





Feedback