Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

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"
GetContentTypesInSite

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

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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

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

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

 
discard

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.