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?