As part of a new SharePoint 2010 project I am trying to automate the build of the SharePoint site on our staging system using NAnt, something we use a lot with our C# builds.
I have created a PowerShell script that I have tested successfully:-
#Load SharePoint cmdlets
& "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG POWERSHELL\Registration\sharepoint.ps1"
# Create the site based on blank site template (STS#1)
$template = Get-SPWebTemplate "STS#1"
$date = Get-Date -format "yyyy-MM-dd HHmm"
$siteURL = "http://MY-PC/SITE " + $date
$siteName = "SITE " + $date
New-SPWeb -Url $siteURL -Template $template -Name $siteName -AddToTopNav
I then created a NAnt file with the following exec call:-
<exec failonerror="true" program="${powershell.exe}">
<arg value="-noprofile" />
<arg value="-nologo" />
<arg value="-noninteractive" />
<arg value="-command" />
<arg value=" " & '${createsite.ps1}' " " />
</exec>
Where ${powershell.exe} -> C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe and ${createsite.ps1} is the full path of my powershell script.
But when I run this I get the following error:-
[exec] Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
[exec] 2.
[exec] At C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONF
[exec] IG\POWERSHELL\Registration\sharepoint.ps1:3 char:13
[exec] + Add-PsSnapin <<<< Microsoft.SharePoint.PowerShell
[exec] + CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShel
[exec] l:String) [Add-PSSnapin], PSArgumentException
[exec] + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
[exec] dPSSnapinCommand
I thought this was due to my not referencing the SharePoint PowerShell snap in correctly, so changed
& "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\sharepoint.ps1"
to this
Add-PSSnapin Microsoft.SharePoint.PowerShell
with no effect.
Does anybody have any experience of running PowerShell with NAnt and have any suggestions?
Thanks.
Update
As per Micks reply, the process was indeed calling the 32 bit version of PwerShell. Turns out Microsoft redirects you from the 64 bit folder when running a 32 bit process. For now, I've created an NTFS Junction that points to the 64 bit directory for PowerShell and pointed to that in my NAnt script.