I have this function:
function start-sqlsnap
{
add-pssnapin SqlServerCmdletSnapin100
}
Regardless of the method used to load the function, get-pssnapin will show the snapin loaded. However:
- If pasted in the shell, the functions (like invoke-sqlcmd) are recognized
- If dot sourced from a file, the functions are recognized
- If placed in a psm1 file (inside the module folder, in its own folder with the same name as the psm1 file) and loaded with import-module, the snapin specific functions are not recognized ā but running get-pssnapin will show the module as loaded.
Error:
The term 'invoke-sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ invoke-sqlcmd <<<<
+ CategoryInfo : ObjectNotFound: (invoke-sqlcmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I tried the same thing with a different snapin: Microsoft.EnterpriseManagement.OperationsManager.Client and had the exact same result. Iām running PowerShell 2 on 2008 R2.
Is this a known bug or feature? Can I solve this somehow?