Posts Tagged 'sharepoint'

How to export and import lists and libraries from a SharePoint 2010 site using Powershell

Let’s imagine this scenario:

You have an old SharePoint 2010 site and you need to copy its content to another SharePoint farm.  The site is heavily customized and moving it using traditional methods (backup/restore, export/import, save site as a template) are not going to work well.  Plus you only want content – no need to bring in all of that custom branding baggage.

You can copy the content using PowerShell and two scripts shown below.

Script # 1:   Export all lists and libraries from the source site.


add-pssnapin microsoft.sharepoint.powershell

# specify the site URL to export

$web = Get-SPWeb "http://sharepointURL/sites/site1/web1"

# specify output folder to store exported lists

$path = "c:\admin\export\"

foreach($list in $web.lists)

{

"Exporting " + $list.RootFolder.URL

export-spweb $web.URL -ItemUrl $list.RootFolder.URL -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile

}

The output of this script should be a number of CMP files in the output directory.  Review these files and remove the lists that should not be imported (such as various Gallery lists).

Script # 2:  Import CMP files into the destination site.


add-pssnapin microsoft.sharepoint.powershell

# specify target SharePoint site to import into

$site = "http://sharepoint/sites/test1"

# specify folder containing exported lists

$folder = "C:\Admin\Import\"

$Files = Get-ChildItem $folder

foreach ($file in $files)
{

$name = $file.Name

"Importing: " + "$folder$name"

import-spweb $site -path ("$folder$name") -includeusersecurity -nologfile

}

Advertisements

Creating a SharePoint 2010 Search Service application using PowerShell

Here’s a great script by Jeremy Jameson on how to create a SharePoint 2010 Search service application with Powershell.

http://blogs.msdn.com/b/jjameson/archive/2011/02/28/powershell-script-to-configure-search-in-sharepoint-server-2010.aspx

I was even able to use it to configure search on a SharePoint 2010 server which was not joined to the domain (as sometimes is required for DMZ deployments).  It worked beautifully using local computer accounts.   There is a change that needs to be made to the script if you’re using local accounts:

Add ShareName and Index arguments as shown below.

$queryComponent = New-SPEnterpriseSearchQueryComponent -QueryTopology $queryTopology -IndexPartition $indexPartition -SearchServiceInstance $queryInstance -Debug:$false -ShareName  <SHARENAME>  -IndexLocation <INDEXLOCATION>

 

Create and delete SharePoint list views with PowerShell

Here’s how you can create and delete views in a SharePoint list or library using PowerShell (Is there anything that can’t be done through a PowerShell script?)

The script below creates a view called “TestView”.  It expects three command-line arguments:  site collection URL, the name of the view to create, and the list GUID.  The view that’s created is an exact replica of the “All Items” view (you can certainly modify the code as needed).  Here’s how you would call this script from the command line:


powershell  CreateView.ps1 "your_site_collection_URL" "TestView" "List GUID 6865306f-60e0-4889-addd-4fb9862e72e0"

Script code (use the button in the top right corner to copy it to the clipboard):


[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

# reading command line arguments

$siteURL = $args[0]

$strViewName = $args[1]

$ListGUID = $args[2]

# enter your CAML query for the view here...

$strQuery = "<Where><Gt><FieldRef Name='ID'/><Value Type='Counter'>0</Value></Gt></Where>"

 # create a new SPsite object and recursively go through all webs

# until a matching list GUID is found

$site=new-object Microsoft.SharePoint.SPSite($siteURL)

foreach ($web in $site.AllWebs)
{
 

foreach ($list in $web.Lists)
{

$ListTempGUID = $list.ID.ToString()
  

if ($ListTempGUID.Contains($ListGUID))
{

write-host "**********************************************"
write-host "Match found. Preparing to create a view: ", $strViewName
write-host "List Title: ", $list.Title
write-host "List GUID: ", $list.ID

$fields = $list.Views["All Items"].ViewFields.ToStringCollection()

$result = $list.Views.Add($strViewName, $fields, $strQuery, 100, $True, $False , "HTML", $False)

write-host "View ", $strViewName , " was created successfully."

break

}
}

} 

write-host "Done."

$site.Dispose(); ##ENFORCED DISPOSAL!!!

    

So far, so good?  Well, now that you’ve created a view, how do you delete it?  Follow the same logic, only instead of using the Add method of SPViewCollection object, we’ll be using the Delete method.

Same command line arguments as before:  site collection URL, name of the view, and list GUID.

Calling script from the command line:


powershell  DeleteView.ps1 "your_site_collection_URL" "TestView" "List GUID 6865346f-60e0-4889-addd-4fb3862572e0"

 


[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

# reading command line arguments...

$siteURL = $args[0]

$strViewName = $args[1]

$ListGUID = $args[2] 
# creating a new site object and recursively searching through its lists

# until a matching list GUID is found

$site=new-object Microsoft.SharePoint.SPSite($siteURL)

foreach ($web in $site.AllWebs)
{
 

foreach ($list in $web.Lists)
{

$ListTempGUID = $list.ID.ToString()
  

if ($ListTempGUID.Contains($ListGUID))
{
foreach ($view in $list.Views)
{

If ( $view.Title.Contains($strViewName))
{

write-host "**********************************************"
write-host "Match found. Preparing to DELETE a view: ", $view.Title
write-host "List Title: ", $list.Title
write-host "List GUID: ", $list.ID

# you can insert a pause here if you like...

$list.Views.Delete($view.ID)

write-host "View ", $view.Title , " has been deleted successfully."

break

}
}

break

}

}

}
write-host "Done."

$site.Dispose(); ##ENFORCED DISPOSAL!!! 
 

Finally,  how do you find out the GUID of your list?  It’s fairly straightforward – you just need to access the SPList.ID property of your list.  Here’s a simple script that will output the GUIDs of all lists in your site collection:


[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null
# write column headings

write-host "List URL ; Web URL ; Web Title ; List Title; List GUID ;"

# create a site object and recursively list all of its list objects and their details
 $site=new-object Microsoft.SharePoint.SPSite("http://your_site_collection_URL)  

  foreach ($web in $site.AllWebs)
 {
  foreach ($list in $web.Lists)
 {
 write-host $list.DefaultViewURL, ";", $web.URL , ";",  $web.Title , ";" , $list.Title , ";" , $list.ID

 }

 }

$site.Dispose(); ##ENFORCED DISPOSAL!!!

Calling STSADM from within a PowerShell script

For various SharePoint admin tasks, there are times when you need to execute an STSADM command from within a PowerShell script. 

Before you can do that, you’ll need to tell PowerShell where to find STSADM executable. You can do that by adding the following line to your profile.ps1 file (usually located in C:\WINDOWS\system32\windowspowershell\v1.0 ):

Set-Alias -Name stsadm -Value $env:CommonProgramFiles”\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE”

Now you can use stsadm in your scripts and it should work beautifully…

Content Deployment error: Maximum request length exceeded.

Sometimes, when you run a Content Deployment job between a source farm and a destination farm, you may encounter the following issue:

“Content deployment job ‘Job Name’ failed. The remote upload Web request failed.”

When you look in the ULS logs, you may see the following:

File upload of ‘C:\Inetpub\wwwroot\SiteDirectory\ExportedFiles70.cab’ failed. Exception System.Web.HttpException: Maximum request length exceeded.  at System.Web.HttpRequest.GetEntireRawContent()     at System.Web.HttpRequest.get_InputStream()… 

OK, let’s do a web search to see how to fix this issue.  After some searching, you’ll come across posts that tell you to modify maxAllowedContentLength or MaxRequestLength attribute in the Central Administration web.config file (or maybe WFE’s too).  Examples: 

http://technet.microsoft.com/en-us/library/dd795107.aspx

http://weblogs.asp.net/hosamkamel/archive/2007/09/18/resolving-maximum-request-length-exceeded-exception.aspx

I’ve found that if you only modify web.config files as specified in the articles above, it will NOT solve the problem.  

 To solve this problem, you need to increase maxRequestLength value in three places on the TARGET farm:  

  1. Central Administration web.config file (typically located in C:\Inetpub\wwwroot\wss\VirtualDirectories\DirectoryName)
  2. Your web application main web.config file (typically located in C:\Inetpub\wwwroot\wss\VirtualDirectories\DirectoryName).
  3. Content deployment web.config file located in:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\ADMIN\Content Deployment

Note:  You can find out the correct paths for items 1 and 2 by opening IIS Manager.

Open web.config file located at each location and locate the maxRequestLength attribute.  Increase it to allow upload of the largest CAB file that you have.  The default setting limits the upload file size to 51200 KB for CA and web application and to 102400 KB for content deployment.

<configuration>
  <system.web>
    <httpRuntime maxRequestLength=”102400″ />
  </system.web>
</configuration>

You can find out how large the largest CAB file is by running the following command on the source farm Central Administration server:

stsadm -o editcontentdeploymentpath -pathname (pathname here) -keeptemporaryfiles Failure

 This setting will allow you to see the CAB files generated during the content deployment job (in the temp directory specified in the Content Deployment settings screen in Central Administration).

Why Knowledge Management matters…

I believe that we are standing at the edge of the next big thing in enterprise management – using technological tools to capture, preserve, and maintain the intellectual capital of organizations. I believe that corporations will begin realize that they are investing large sums of money in their employees, but they’re not capturing, preserving, and leveraging the output of these workers. Doing so was very difficult in the past, but it’s doable with today’s tools and platforms such as SharePoint.

I look at it this way… Let’s assume we have a generic mid-level employee who is paid $50K per year. She starts on January 1st, works 50 weeks, and quits on December 31st. At the end of her tenure, this worker has accumulated a year’s worth of knowledge, skills, and experiences about the organization. The company has invested $50K into this individual plus training costs, benefits, etc. After the worker leaves, what does the company have to show for their investment? Maybe some documentation, maybe some training and some skill transfer to another employee, done in a disorganized fashion and varying from manager to manager. And that’s it?? This is an outrageous waste of money and resources. From the first time I saw it even to this day, I can hardly believe it’s happening. Do you find it outrageous too?

If you and I purchased a machine or a product that only lasted a year and which did work for us and also collected information and knowledge about our company, and we paid $50K to use it for only one year – we would want to see some information in the end, wouldn’t we? We would DEMAND to see some reports and graphs and statistics. But not so with employees – we let them work, accumulate knowledge and skills, and then we let them leave… And what about an employee who stays for 5 years and then leaves? Or a higher level employee who makes $100K per year? Or how about a 5-year employee who makes $100K per year? What’s the price tag on that?

We need to have systems and platforms in place that capture, organize, and preserve the intellectual capital produced by today’s knowledge workers. These systems need to be transparent and intertwined with the organization’s business processes and LOB systems. You can’t expect a knowledge worker to go into a separate system and consistently record their knowledge – it just won’t happen. You’ll get output from workers who have a lot of free time on their hands and are probably not the best sources of knowledge. KM needs to happen behind the scenes, in such a way that people don’t even realize they’re doing KM.
I believe that Microsoft SharePoint and other similar technologies offer a platform that will enable organizations to do effective knowledge management. And we’re going to see major changes in how organizations manage the knowledge of their workers…


RSS Information Week Headlines

  • An error has occurred; the feed is probably down. Try again later.

RSS SharePoint Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS InfoPath Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Joel Oleson Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Susan Hanley’s KM Blog

  • An error has occurred; the feed is probably down. Try again later.

Blog Stats

  • 356,734 hits