Open stevebeauge opened 8 years ago
Hmmm, interesting. I think the snapInsToLoad
idea is a good one to solve this problem. I'm not sure if the logic to load .psc1 files is available to anything other than powershell.exe so we might not be able to use that. I'll do a little research.
For now your best bet may be to have a launcher script which calls Add-PSSnapIn
and then dot-sources the script you're trying to test. You'd then run the launcher script so that everything gets loaded up correctly. Let me know if this approach works for you and then I'll see if we can get a better solution working for the next release.
You were right. I can add a launch script run.ps1
that contains:
Add-PSSnapin Microsoft.sharePoint.PowerShell
. .\MyActualScript.ps1
thanks for the suggestion
I'm trying to debug a bunch of SharePoint scripts.
These scripts starts with
#requires -PSSnapin Microsoft.SharePoint.PowerShell
in order to tell Powershell to require a specific snapin to be loaded.With Powershell, we can load a snapin either by calling
Add-PSSnapin Microsoft.SharePoint.PowerShell
prior to run the script, or by running a custom PowerShell console (a.psc1
file). The custom console can target when launching PowerShell :powershell.exe -PSConsoleFile c:\path\to\console.psc1
.using VSCode, I wasn't able to inject the snapin.
I tried to tweak the
launch.json
file like this:or
The error is always:
The script 'test.ps1' cannot be run because the following Windows PowerShell snap-ins that are specified by its "#requires" statements are missing: Microsoft.SharePoint.Powershell.
Did I missed something ? Maybe supplemental parameters to the configuration would be simplier. Either
"consoleFile" : "path\to\psc1file.psc1"
"snapinsToLoad" : [ "snapin1", "snapin2" ]
"modules" : ["custom.module","another.module"]
Thanks