0

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?

1

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'  
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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