Powershell: Efficiently empty large SharePoint lists

03 May
May 3, 2013

Previously I had a little console app to efficiently empty large SharePoint lists. Today I converted it to powershell.

Compared to the simple item by item delete with item.Delete() its 30 times faster; on my dev machine it deletes ~30 items per second. It works for SharePoint 2010 and should  for 2013 (not tested, yet).

Script

param($weburl,$listname)
 
if ($weburl -eq $null -or $listname -eq $null)
{
	write-host -foregroundcolor red "-weburl or -listname are null."
	return
}
 
Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0
$web = get-spweb $weburl
$list = $web.lists[$listname]
 
$stringbuilder = new-object System.Text.StringBuilder
 
#TODO: fetch items with spquery
 
try
{
    $stringbuilder.Append("<!--?xml version=`"1.0`" encoding=`"UTF-8`"?-->") &gt; $null
 
	$i=0
 
	$spQuery = New-Object Microsoft.SharePoint.SPQuery
	$spQuery.ViewFieldsOnly = $true
 
	$items = $list.GetItems($spQuery);
	$count = $items.Count
 
	while ($i -le $count)
	{
		write-host $i
		$item = $items[$i]
 
        $stringbuilder.Append("") &gt; $null
        $stringbuilder.Append("" + $list.ID + "") &gt; $null
        $stringbuilder.Append("" +$item.Id + "") &gt; $null
        $stringbuilder.Append("Delete") &gt; $null
        $stringbuilder.Append("") &gt; $null
 
		$i++
    }
    $stringbuilder.Append("") &gt; $null
 
    $web.ProcessBatchData($stringbuilder.ToString()) &gt; $null
}
catch
{
	Write-Host $_.Exception.ToString()
}
 
write-host "done."

Usage

Delete-Items.ps1 -weburl [url of web] -listname [name of list]

Further improvements

I think if the list is really huge (100k items or greater) the items should be deleted in batches.

I have not tried it with a document library, maybe there are issues. If there are issues, please leave a comment!

Disclaimer

There is no way back – if you start the script there is no “ARE YOU SURE?” – all data is gone in a very short time.

ShareCamp 2013 – Recap and session slides

15 Apr
April 15, 2013

ShareCamp 2013 took place at Microsoft’s office here in Munich last weekend (4/12/2013-4/14/2013) and it was a BLAST.

sharecamp

Sharecamp 2013 – before it began. Picture taken by Michael Greth

 

sharecamp_start

Saturday, 9:00am.

sharecamp_sessionplaning

200 SharePointers voting for sessions

What I totally like was the open but still professional style of the barcamp – every attendee was allowed to suggest one or more presentation topic. After receiving more than 5 votes from the 200 attendees you got a session slot assigned (room and time). Meeting friends, colleagues, 5 MVPs (Michael Greth, Christian Glessner, Niki Borell, Daniel Wessels and Fabian Moritz) and other experts (from Microsoft, too) was really cool and I learned a lot, again!

No promotion in my company was needed, more than 10 colleagues attended  – Sebastian Huppmann gave a nice presentation on Saturday about Twitter’s Streaming API – and it was the first year that Alegri sponsored the event.

Session: “Search Architecture” by Rainer Asbach, Microsoft

Every time Rainer Asbach is speaking I try to attend. Very, very profound search-expertise – I attended 2 years ago – now again and it was very interesting again!

Key take aways:

  • Search Index is now smaller, FIXML of FAST not stored anymore. Index should be noticeable smaller than with FAST for SharePoint 2010.
  • Better understanding how search is scaled and how to utilize critical services – great video how the crawler/query component hits CPU/RAM and how that affects DB/Webfrontends/Index/Analytics etc.
sharecamp_searcharchitecture

Rainer Asbach – Search Architecture

 

Session: “Search-driven Apps with SharePoint 2013 – what’s possible with the new platform?”

Presented my favorite topic – Search – in front of roughly 50 people I showed what the new platform is capable of. From continuous crawling to content by search webpart I covered a lot of stuff and answered even more questions. Had fun!

Sharecamp_Search

Presenting at ShareCamp 2013 – I am the guy with the red shirt

 

Slides: available at slideshare

Session: SharePoint 2013 / Best Tools / Toolbox + automated SharePoint 2013 Installation

Again, 50 people attended my session about tools. This time I showed how to install SharePoint 2013 fully automated with PowerShell – the awesome AutoSPInstaller raised a lot of questions and kept the session very interactive. I was really surprised that only 20% of the audience knew it…

Apparently I could not show the final result, I will record a webcast for the SharePoint Toolbox and you can see the result there.

After showing how to configure the AutoSPInstaller (briefly) – I showed how to install other tools via chocolatey (8 SharePoint tools are available by now).

Then we discussed some tools but ran out of time because I talked too much! My bad. Here is the list of the tools we collected:

UlsViewer (two guys in the audience did not know this gem!)
Chocolatey
Caml Designer (see webcast )
CKSDEV (webcast, new version for 2012 available)
Sharepoint Manager (2007 / 2010 / 2013)
Health check rules (new one for me, will check it out!)
SPServices
Blob Cache Manager (SP2010 and SP2013)
SP2010 Batch Edit (want to batch edit list entries with managed Metadata in SP2010? This is a solution…)
SPWakeUp (a handy solution for the sleepy SharePoint)
Microsoft Remote Desktop Connection Manager (new for me, sounds great!)
Dynamic Forms for SharePoint (adjustable forms for SharePoint to save data to a list with rules and styles)
SPSin (inject JavaScript and CSS into selected SharePoint pages)

Slides: available at slideshare

Final notes

Thanks everyone for organizing this great, great event – I will attend next year, promised. Hopefully no relocation next year so I can attend both days and can join more sessions and discussions.

 

 

FAST for SharePoint 2010 – Cumulative Update August 2012

05 Apr
April 5, 2013

The Cumulative Update August 2012 for FAST Search Server for SharePoint 2010 is out for a while now – seems like nobody has tried this one yet. Or quality control has happened…

Updating FAST Search

When you install a service pack or a cumulative update for FAST you have to run the setup and then you have to start a FAST powershell and start “psconfig –action p” – otherwise your search won’t work because SAM Worker process is dead.

Cumulative Update August 2012

So what happens when you install the update? The installation went fine – I rebooted my server and then, as usually, I started the powershell to start the patch command! BAM!

PS C:\FASTSearch\installer\scripts> .\psconfig.ps1 -action p
At C:\FASTSearch\installer\scripts\include\commontasks.ps1:169 char:58
+     $hostname = ReadHostConfigurationProperty -propertyName
$script:$HOST_CONFIG_HO ...
+                                                             ~~~~~~~~
Variable reference is not valid. '$' was not followed by a valid variable name
character. Consider using ${} to delimit the name.
+ CategoryInfo          : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : InvalidVariableReference

IsPostSetupConfigured : The term 'IsPostSetupConfigured' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\FASTSearch\installer\scripts\psconfig.ps1:670 char:17
+     $isInstalled = IsPostSetupConfigured
+                    ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (IsPostSetupConfigured:String) [
], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
fast_cu2012_aug_patchfail

Epic quality check fail!

Wonderful!

Solution

At least the fix for this problem is quite simple – and the powershell error is really helpful this time.

Open the file “<FASTInstall>\installer\scripts\include\commontasks.ps1” and go to line 169. Replace $script:$HOST_CONFIG_HOST_NAME with $script:HOST_CONFIG_HOST_NAME. Save the file and then start the patch again with “psconfig –action p” in the installer\scripts folder. After patching check with nctrl status if the SAM Worker is alive again.

fast_cu2012_aug_patchfix

Easy fix – just remove the $

Still, unbelievable.

#SharePoint 2013 Search – The gatherer service cannot be initialized

19 Mar
March 19, 2013

I installed SharePoint 2013 on a test system yesterday and was faced with the problem that the search, after successfully provisioning it – did not work. Boo!

Symptoms

There are several noticeable Symptoms

The crawl log shows 1 Top Level Error and 1 Error:

image

Crawl log with 1 Top Level Error and 1 Error

The Eventlog shows some warnings and an error

Error_2

Eventlog with the error “The gatherer service cannot be initialized”

with the following text – not the best error description (again):

The gatherer service cannot be initialized.
Details:
The Temp folder is on a drive that is full or is inaccessible. Free up space on the drive or verify that you have write permission on the Temp folder.   (0x80070660)

Solution

In my case the solution was quite simple. The Temp folder is not the %WINDIR%\Temp or C:\Temp folder – it’s the location of the search index. I installed SP2013 with AutoSPInstaller (<= highly recommended!) with default values, then the index is located in C:\Program Files\Microsoft Office Servers\14.0\Data\Office Server\Applications

If you provisioned the Search Service with my powershell script – then you can customized the Index Location with the $IndexLocation variable in the settings region.

I can’t tell yet if that problem is related to my installation –. I tried to get more information about this problem and it seems like this could happen if you relocated your index, too.

Now to fix the problem, modify the permissions of the Applications folder or the parent folder of your search location.

Grant the local WSS_WPG group at least modify permissions on the folder – in my screenshot I granted full control, it’s just a test system…

Then restart the Search Service, easiest with PowerShell:

Restart-Service osearch15
Permissions

Altered permissions to fix the issue

Did it work for you?

If (not) – would love to hear your feedback!

Chocolatey: Created two new SharePoint “Helpers” for lazy developers

12 Mar
March 12, 2013

I mentioned Chocolatey and Powershell quite often in the last time, today I created two little helpers and uploaded them to the chocolatey gallery.

The two super-awesome (and simple) packages called SharePoint.HiveShortcut.Desktop and SharePoint.HiveShortCut.Explorer – and the name indicates it, they create shortcuts to the hive folder.

I could just upload the two lines of powershell on this blog, but I totally like the Chocolatey approach – makes it easy for everyone.

Video or it did not happen!

Why you need the Hive-folder?

Good question, most of the time if something is not working as expected. Ever wondered if a feature is where it should be? Images missing? Unsupported customizations? 14-/ 15- folder is the place to go.

Links

SharePoint.HiveShortcut.Desktop: Chocolatey Gallery

SharePoint.HiveShortcut.Explorer: Chocolatey Gallery

Github repository for all my SharePoint chocolatey packages.

Next tools for Chocolatey

On my personal roadmap are two tools which will be available on the chocolatey gallery very soon.

  • SharePoint Manager
  • Caml Designer

Something missing?

Go drop me a line or use the comments!

SharePoint Toolbox #012: AutoSPSourceBuilder

11 Mar
March 11, 2013

Today a new webcast on the SharePoint Toolbox was released. It’s about the very cool AutoSPSourcebuilder powershell script.

Summary

The webcast shows you how to create SharePoint 2013 installer package with bundled Prerequisites (so you can install SharePoint without Internet-Connection) and includes the SharePoint 2013 Cumulative Update December 2012. Language packs or even Service packs could be added, too.

Its available in English and German.

Feedback, questions or tool suggestions much appreciated.

Powershell: List all IIS WebApplications (.net version, state, identity)

06 Mar
March 6, 2013

Short powershell script to list all IIS Web Applications with the .net version, the state of the Web Application and the assigned user/identity.

try{
Import-Module WebAdministration
Get-WebApplication
 
$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}
 
$item.WebAppName = $webapp.name
$item.Version = (Get-ItemProperty $name managedRuntimeVersion).Value
$item.State = (Get-WebAppPoolState -Name $webapp.name).Value
$item.UserIdentityType = $webapp.processModel.identityType
$item.Username = $webapp.processModel.userName
$item.Password = $webapp.processModel.password
 
$obj = New-Object PSObject -Property $item
$list += $obj
}
 
$list | Format-Table -a -Property "WebAppName", "Version", "State", "UserIdentityType", "Username", "Password"
 
}catch
{
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
$ExceptionMessage
}

And the output is a nice table:

WebAppName Version State UserIdentityType Username Password
SharePoint – 80 v2.0 Started SpecificUser demo\spservices pass@word1

Chocolatey Package: SharePoint 2013 Search Query Tool

09 Feb
February 9, 2013

I am a huge fan of automation and powershell  - this should explain why I really love chocolatey (a package manager to install software with powershell).

Today I created a new feed for SharePoint 2013 Development Tools: http://www.myget.org/feed/Packages/sharepoint2013dev and uploaded the very cool SharePoint 2013 Search Query Tool to the chocolatey gallery. This tool helps creating and testing search querries – and search is everywhere in SharePoint 2013!

 

After installing chocolatey you can get a great starter toolset with one line of powershell:

cinst all -source http://www.myget.org/F/sharepoint2013dev

This installs 18 tools for SharePoint 2013 development – all of my favorites are included. I maintain a second feed on MyGet for SharePoint 2010 tools, I guess the SP2013 feed will grow and diverge over time.

SharePoint 2013 Design Manager: Map network drive on Windows Server 2012

07 Feb
February 7, 2013

So the best way to adjust and edit MasterPages and DisplayTemplates in SharePoint 2013 is to map a network drive and edit the files directly there or copy them to this location.

If your SharePoint is hosted on Windows Server 2012 this does not work without configuration – I am really surprised that the config wizard or the PreRequisite Installer does not add the required service – but lets just focus on the solution.

Solution

Open the Server Manager.

image

Click next until “Features”.

image

Expand the greyed-out “User Interfaces and Infrastructure”, check the Desktop Experience entry (I took the screenshot after installing it).

image

Click next and install the feature. Then you have to reboot the Server.

After the reboot open the Service Manager (services.msc) and start the WebClient service – and if you want set it to automatic start so it works after the next reboot.

image

After this open an explorer and try to connect to \\<hostname>\_catalogs\ and the result should look like this:

image

Cache cluster is down, restart the cache cluster and Retry

05 Feb
February 5, 2013

Had a small issue with my SharePoint 2013 MySite today, I could not update a User Profile in Central Admin – this is what I got from the ULS Log:

sp2013_cachecluster

ULSViewer: The exception is pointing us in the right direction.

The Execute method of job definition Microsoft.Office.Server.UserProfiles.LMTRepopulationJob (ID 104963a2-b53c-4476-bc23-fa7d6453e42f) threw an exception. More information is included below.  Unexpected exception in FeedCacheService.IsRepopulationNeeded: Cache cluster is down, restart the cache cluster and Retry.

At least the error message pointed me to the right direction, the Cache Cluster is new in SharePoint 2013 and I associated it with the app fabric distributed cache. As I first read it it sounded like “The King is dead – long live the King!” – but maybe I watch to many movies…

Solution

Restart the app fabric service and wait a couple of second with a line of powershell:

Restart-Service AppFabricCachingService