SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning Powershell, I have this line at the top of example script, but it doesnt appear to be necessary. What does it do? Why would it be there?

# SharePoint DLL

For example this example script to get content types works if the above line is commented out.

# SharePoint DLL    
# COMMENTED [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Cmdlet Install
 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Get content types in a site collection.
# ----------------------------------------
function GetContentTypesInSite()
    $site = new-object Microsoft.SharePoint.SPSite($SiteURL)

    $web = $site.rootweb.ContentTypes
    ForEach ($id in $web)
         '"' + $id.Name + $id.Id + '"'  | Out-File $OutputFile -append

$SiteURL = "http://server:33333"
$OutputFile = "C:\temp\contenttypes.txt"

I'm using the Windows PowerShell ISE to run the scripts

share|improve this question
up vote 9 down vote accepted

This used to be the way to load the sharepoint c# library in sharepoint 2007


In sharepoint 2010 this command does the same thing and more (adds 2010 commandlets)

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

There is usually no harm in running both, and it gives you consistent includes across versions

And if you use the sharepoint powershell command line, it will do the includes for you

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.