Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created a Powershell script to install my solution. The script consist of several tasks, one is deploying a solution which contains a custom service application along with powershell cmdlets. The solution deploys an xml to the Powershell registration folder. The problem is, I want to use the commands mentioned in that XML in my script, but Powershell understandably complains about not recognizing the cmdlet.

So I tried unloading and loading the sharepoint pssnapin in the hope that this would also reload the xml registrations:

Write-Host "Reloading snap-in to load the freshly published DLLs" -ForegroundColor yellow
Remove-PsSnapin Microsoft.SharePoint.PowerShell
Add-PsSnapin Microsoft.SharePoint.PowerShell

But that didn't work. I think the entries are cached in the session so they don't get reloaded. When I close my Powershell window, open a new one and try the same commands again; they work as expected. So how can I mimic that behaviour inside my session?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You can put the part of your script using the "new" cmdlets into a new script file (starting with Add-PSSnapIn Microsoft.SharePoint.Powershell) and the launch a separate powershell process running that something like this:

$arg = "-file `"SecondScriptName`"" 
Start-Process "$psHome\powershell.exe" -ArgumentList $arg -ErrorAction 'stop'  
share|improve this answer
    
Ok, but does that mean there's no way to do it in the same session? –  Jasper Jul 25 '12 at 7:28
1  
I don't think you can do it in the same session, but anyway you should get used to spawning up new sessions when using PowerShell to deploy with SharePoint as you'll also often run into problems with old versions of assemblies already being loaded, when you update. –  Per Jakobsen Jul 25 '12 at 11:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.