Archive

Archive for January, 2012

Getting A List of SharePoint 2007 Email Enabled Document Libraries using PowerShell

January 19, 2012 1 comment

In the process of migrating between MOSS 2007 and SharePoint 2010 I needed to get a listing of all Email Enabled Document Libraries/Lists in my MOSS 2007 environment prior to migration.  This could be accomplished with a little bit of coding with the SharePoint API, but why do that when you can do it with PowerShell.

First and foremost if you haven’t already installed PowerShell 2.0 onto your MOSS 2007 server go to http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20430 and download the lastest version. Since PowerShell does not come native with MOSS 2007 this needs to be installed individually before we can begin.

After installing PowerShell 2.0 we are going to be creating a .ps1 file.

Open up any text editor (my choice is notepad).

First thing we want to do is load the SharePoint Assemblies so that PowerShell knows how to process MOSS 2007 commands.  Assemblies do not have to be loaded into SharePoint 2010.

#Load SharePoint Assemblies
[System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

Next Instantiate a SPWebApplication Object

#Instantiate a SPWebApplication Object
$SPWebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(http://portal)

Next Lets Create a CSV file
#Create a CSV file Email-Enabled.txt
“E-Mail,List,Site”  > “EMail-Enabled.txt” #Write the Headers in to a text file

Now Create a ForEach loop to loop through the SharePoint Web Applications, Sites, Subsites, and Lists to gather all Email Enabled Document Libraries and pipe it out to the Email-Enabled.Txt file we created.

foreach ($SPsite in $SPwebApp.Sites)  # Get The Collection of Site Collections
{
foreach($SPweb in $SPsite.AllWebs)  # Get The Collection of Sub Sites
{
foreach ($SPList list in $SPweb.Lists)  # Get The Collection of Lists.
{
if ( ($splist.CanReceiveEmail) -and ($SPlist.EmailAlias) )
{
# WRITE-HOST “E-Mail -” $SPList.EmailAlias “is configured for the list “$SPlist.Title “in “$SPweb.Url
$SPList.EmailAlias + “,” + $SPlist.Title +”,” + $SPweb.Url >> EMail-Enabled.txt  #append the data
}
}
}
}

So your final script should look like this:

#Load SharePoint Asssemblies
[System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

$SPWebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(http://portal)

#create a CSV file
“E-Mail,List,Site” > “EMail-Enabled.txt” #Write the Headers in to a text file

#Create foreach loop to enumerate through SharePoint Web Application, Sites, Subsites, and Lists.  
foreach ($SPsite in $SPwebApp.Sites)  # get the collection of site collections
{
foreach($SPweb in $SPsite.AllWebs)  # get the collection of sub sites
{
foreach ($SPList list in $SPweb.Lists)
{
if ( ($splist.CanReceiveEmail) -and ($SPlist.EmailAlias) )
{
# WRITE-HOST “E-Mail -” $SPList.EmailAlias “is configured for the list “$SPlist.Title “in “$SPweb.Url
$SPList.EmailAlias + “,” + $SPlist.Title +”,” + $SPweb.Url >> EMail-Enabled.txt  #append the data
}
}
}
}

Save the file as emailenabled.ps1 or which ever name you choose.

Open up PowerShell on your MOSS 2007 Server, and change directories to where the emailenabled.ps1 script was saved.

Execute the script.  Depending on how large your web application is this might take a little bit of time.

After the script completes inside the location where your script sits you will now see a .TXT file named “Email-Enabled.txt”. Inside that text file you will have a listing of all the Email Enabled Document Libraries/Lists within your SharePoint 2007 Web Application.

Import/Export SharePoint 2010 Site Collections

January 18, 2012 Leave a comment

To Export/Import SharePoint 2010 Site Collections follow these simple PowerShell Cmdlts below.

Export

Export-SPWeb -Identity **SITE-URL** -Path **PATH-FOR-EXPORT-FILE** -IncludeVersions All -IncludeUserSecurity

Import

Import-SPWeb -Identity **SITE-URL** -Path **PATH-FOR-IMPORT-FILE** -IncludeVersions Overwrite -IncludeUserSecurity

Finding: A Duplicate Field Name [GUID] Was Found Error in SharePoint 2010

January 18, 2012 7 comments

I was recently Exporting and Importing a SharePoint 2010 Site Collection in my SharePoint environment and I ran into  this error when trying to Import the Exported Site Collection into a brand new Site Collection:

“A duplicate field name “<GUID>” was found”

If you run into this problem, to determine what duplicate field name its causing this error, run this PowerShell script.

1.  Open up notepad, paste the script, change the Get-SPWeb and the “<GUID>” attributes and save the file with the .ps1 extension.

$web = Get-SPWeb “http://portal&#8221;
foreach ($field in $web.Fields)
{
if($field.Id -eq “<GUID>”)
{
write-output “Title: $($field.Title) | ID: $($field.Id)”
}
}
$web.Dispose()

2.  Open up SharePoint 2010 Management Shell, change directory to the location you saved the .ps1.
3.  Execute the .ps1
4.  Once Executed you will see the name of the duplicate field and its ID.

Now you can go back to your Site Collection and delete that duplicate field, and try your Export/Import again.

Delete SharePoint 2010 Lists by using PowerShell

January 11, 2012 5 comments

There might come a time when you need to delete a SharePoint 2010 List and you are unable to due so because the list is corrupted and SharePoint won’t let you delete it.

To delete the list using powershell follow these steps.

1.  Log into the CA or SharePoint Sever
2.  Bring up SharePoint 2010 Management Shell (PowerShell)
3.  Type:  Get-SPWeb “portal url” | % {$_.Lists.Delete([System.Guid]$_.Lists[“name of list”].ID)}
4.  Hit Enter

This will delete the SharePoint list from your site collection.

Go back to your list views to determine that the list was indeed deleted.