Friday, 3 September 2010

SharePoint 2010 PowerShell Useful Scripts

Get Content Types in a Site collection
$site = new-object Microsoft.SharePoint.SPSite(http://ww3.sp.demo.dev/)

$web = $site.rootweb.ContentTypes
ForEach ($id in $web)
{
'"' + $id.Name + $id.Id + '"' Out-File "d:\logfiles\contenttypes.txt" -append
}

Delete a List Instance
$site = new-object Microsoft.SharePoint.SPSite(“http://demo.dev/”)
$web = $site.rootweb
$list = $web.Lists["Orders"]
$list.Delete()
 
Run all time jobs 
$timers=Get-SPTimerJob|{$_.isDisabled -eq $false}
foreach ($timer in $timers) {$timer.RunNow()}
View ULS data for a CorrelationId
PS C:\Users\PaulB> get-splogevent ?{$_.Correlation -eq "fe45a7cd-e91b-4ad3-80dc-50cd2a238c6a"} select Area, Category, Level, EventID, Message Format-List 
Run the SharePoint Health Analyzer
$jobs = Get-SPTimerJob | Where {$_.DisplayName -match "Health Analysis Job"}
foreach($job in $jobs) {
  Write-Host "Running" . $job.DisplayName
  $job.RunNow()
}

Read an XML file:

Not all jobs are fired automatically so you can run all the SP Health Analyzer jobs using this PS cmd.  Ensure server can deal with extra load (run out of hours if possible).
Ari Bakker

Turn On-Off Publishing Workflow
John Livingston
PowerShell Basics
Zach Rosenfield's - Farm settings, retrieve solutions, basic SharePoint operations
Gary Lapointe
Blog

Brian Lalancette
AutoSPInstaller - Installation of SP2010
Use Windows PowerShell to Display Service Dependencies

Adam Preston
Blog
Disable Loopback in IE - New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword

Todd Klindt
Blog

PowerGui
PowerGui SharePoint reference card
Download PowerGui

Add the SP cmdlets to PS window
Add-PSSnapin Microsoft.SharePoint.PowerShell

Get Help about PS Cmds
PS> Get-Help Get- SpWebapplication
http://thuansoldier.net/?p=1559

Updated: 23 Oct 2012
Add a local user account

Add an account to AD and add the account to a group.

Apologies if I have ripped script directly.  I don't have the source for a lot of the work these help scripts are based.  On pls let me know if I need to credit a source.
 

Wednesday, 1 September 2010

SP2010 AutoSPInstaller Prerequisite Install Issues (Codeplex PS project)

Problem: Install SP2010 using the CodePlex PowerShell Installer (AutoSPInstaller) without internet access.

Hypothesis: 
Add the following KB to the prerequisiteInstaller folder:
  • Windows6.0-KB968930-x64.msu (/POWERSHELL)
  • Windows6.0-KB976394-x64.msu (/KB976394)
  • Windows6.1-KB976462-v2-x64.msu (/KB976462)
  • Windows6.0-KB974405-x64.msu (/IDFXR2)
  • rsSharePoint.msi (/ReportingServices)
  • SpeechPlatformRuntime.msi (/Speech)
  • MSSpeech_SP_en-us_tele.msi (/SpeechLPK)
=====

Error: Error.  An unknown error occurred installing prerequisites at c:\....\AutoSPInstaller.sp1:388 char:14 ...

Fix: Reboot server and retry.

=====

Error: The tool was unable to install SQL 2008 R2 Reporting Services SharePoint 2010 add-in. Install process returned (0X643=1603).  Applies to the codeplex Powershell scripted install.
Fix: Only info I found suggested a re-run fixes the error. Simply re-running the prerequisite installer did not fix the issue for me. A similar error suggesting that i am using the incorrect version of rsSharepoint.msi relating to the Genva framework (claims) not Reporting Services.  I tried manually installing the Reporting services rsSharePoint.msi, it kept failing.  I also tried rsSharePoint_x64.msi, also failed.
Next I ran SharePoint install manually after the manual prerequisites was run as Administrator, failed.

Noticed I had 2 rsSharePoint.msi that are of a different size?  The file I used on 2 Sept 2010 on my Win 2008 R2 WFE was 36.9MB in size, my other was 39MB.  rsSharePoint.msi download

I use the version off the SQL media for getting Reporting Services wirking in the SharePoint mode.

=====

Error: rsSharePoint.msi wont install
Fix: There are version versions of rsSharePoint.msi, ensure you use the correct 36.9MB file.
I downloaded the correct version from http://go.microsoft.com/fwlink/?LinkId=192588
Incorrect 39MB Version as of 2 Sept 2010 .
These file have the same name but they are different and using Windows 2008 R2 for my install only the 36.9MB version works.

=====

Installation Notes for a 3 server NLB SharePoint 2010 farm

Tuesday, 31 August 2010

SharePoint 2010 Prerequisite Installation

Problem: SP 2010 has to have prerequisites run that setups and installs software components.  This can be run by clicking the prerequisiteInstaller.exe or via a cmd prompt.  The cmd prompt option is useful for unattended installs.  Additionally the prerequisite installer will access the internet to download the required files, my environment does not have Internet access.

Initial Hypothesis: Download software onto the WFE servers and run the prerequisites to use local copies of the software that is required.

Resolution:
  • Extract SP2010 onto the local WFE
  • Open the PrerequisiteInstallerFiles folder and copy msi's & exe's (Minimal files would be: sqlncli.msi, mschart.exe, dotnetfx35setup.exe, Syncronisation.msi, FilterPack64bit.exe, SQLServer2008_ASADOMB10.msi)
  • Open a cmd prompt and run as an Administrator.
  • Navigate to the appropriate directory using Windows explorer where PrerequisiteInstaller.exe is and create the file PrerequisiteInstaller.Arguements.txt
  • Edit the PrerequisiteInstaller.Arguements.txt file as shown below.  Save and close the files.
  • Navigate to the appropriate directory using the cmd prompt where PrerequisiteInstaller.exe is located and run the cmd "PrerequisiteInstaller.exe".  Mine is c:\Software\SP2010>PrerequisiteInstaller.exe

Tip: The Prerequisiteinstaller.Arguements.txt must not have line breaks between switch statements only spaces.  I.e. the config must be on 1 line.

PrerequisiteInstallerArguements.txt:
/unattended /SQLNCli:PrerequisiteInstallerFiles\sqlncli.msi /ChartControl:PrerequisiteInstallerFiles\MSChart.exe /NETFX35SP1:PrerequisiteInstallerFiles\dotnetfx35setup.exe /Sync:PrerequisiteInstallerFiles\Synchronization.msi /FilterPack:PrerequisiteInstallerFiles\FilterPack64bit.exe /ADOMD:PrerequisiteInstallerFiles\SQLSERVER2008_ASADOMD10.msi

More Info:
Create an "offline" SP2010 prerequisite installer
Prerequisite cmd config options
Pre-requisite software lists
SP2010 install cmd-line args


Monday, 30 August 2010

Linq to SharePoint 2010 DSL extensions

I have been building a composite application for a client that has a heavy reliance on SPMetal.  There are several issues using SPMetal and I have spent time this weekend trying to figure out how SPMetal works so I could work around our issues.  I found this project from MS LINQ to SharePoint DSL extensions.  Pretty impressive tool.

A few years back I went to Microsoft to hear about Domain Specific Languages (DSL), at the time I thought it was pretty amazing but couldn't see any benefit for me and thought it was going to be pretty niche in fields like academic research.  I was wrong and this project is definitely worth a look it you are going to use SPMetal, you may not need or want the extra ability but pretty useful.  Olivier Carpentier has written a good user guide & made a pod cast to go along with the unsupported MS project.

Thursday, 26 August 2010

Creating lookup columns and list declaratively in SP2010

Problem: When creating lists via a feature, you may want to link SharePoint 2010 lists.
Initial Hypothesis: In MOSS to link to SharePoint 2007 lists you had to do it via the UI or via a deployable feature.  The list was created declaratively using XML (CAML).   Lastly the lookup column needed to be created using a feature receiver.  As in MOSS, in SP2010 you can create a lookup column using the UI but this is not a reusable deployment method and falls prey to errors.  SP2010 allows you to create lookup lists using declarative CAML.

Resolution: Create the lists, add site columns (fields), then add the site columns to a content type and lastly generate the list definition & list instance.  Steps are detailed below:
  • In an elements file declaratively create a lookup column that uses the specified list as shown below: 

  • Add the new lookup column to a content type:
  • Your existing/create a list definition that derives from your content type.
Note: The Lookup Site column needs to specify the list it is looking up when you declare the XML.
More Info:
Creating lists declaritively in SP2010 - Post outlines creating SharePoint lists, coupled with this post you can create lists that are related using a feature to create your lists.
Available field types

Wednesday, 25 August 2010

Creating SharePoint Lists declaratively using Visual Studio 2010

Problem: Create a custom list to hold configuration values in a list.
Resolution Overview: Using VS 2010 create a feature that deploys the new list with content.
1.> Create Site Columns/fields;
2.> Create the Content Type using the Site Columns;
3.> Create the List Definition from the Content Type; and
4.> Add items to the list instance elements.xml.

Resolution Steps:

1.> Create Site Columns by adding a new "Empty Element" item in VS.
Declaratively add the site column to the elements.xml file;
Ensure your element file has been added to a feature for deployment;
Deploy the feature and ensure the Site Column has been add using the UI "Site Setting" > "Site Columns";

2.> Create the Content Type using the Site Columns
Using VS 2010 create a new Content Type;
Add caption
Using the existing Site Column create the Content Type declaratively;
Check the Content Type is create after you have deployed; 

3.> Create the List Definition from the Content Type

Follow the wizard and select the newly created Content Type "Configuration";
Check the List definition has created the elements.xml and schema.xml files;

Edit the Schema.xml File to Show the new columns defined int he content type (otherwise you will only see the "Title" column);

4.> Add items to the list instance elements.xml

Ensure the List is created



Tip: The fields/site columns & FieldRefs used in the elements files can be added thru the VS2010 tools.  VS2010 > View > Toolbar
Tip: Updated 18 Oct 2010 - CKSDev has the functionality to import Site Columns, this is useful in that you may of created the SiteColumns via the UI on a prototype site and you can not easily get the xml to create the site columns/fields declaritively.  http://blog.mastykarz.nl/cksdev-support-importing-site-columns/

Sandbox solution deployment error

Problem: Deploying a solution package to a sandboxed site using Visual Studio 2010 I receive the error "Error occurred in deployment step 'Activate Features': Timeout occurred while running the SharePoint Sandboxed Code service. This service is required to run sandboxed solutions in SharePoint.  Please ensure the service is configured correctly in SharePoint.". 
Resolution: I restarted my "SharePoint 2010 User Code Host" Windows Service.


More: Common error after initial install of SharePoint Error: Cannot start service SPUserCodeV4


http://www.sharepointdevwiki.com/display/spadmin2010/Configuring+Sandboxed+Solutions+-+Cannot+start+service+SPUserCodeV4+on+computer