0

I have a (pretty much clean) Windows Server 2008 R2 Build with SQL Server 2012 installed. I'm having a problem with PowerShell (Version 3).

I am trying to use the Invoke-Sqlcmd cmdlet. However, when I call get it i get a message saying that 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program.

It works if if I run Import-Module SqlPs -Verbose -Force (bypassing the security policy). However it this lasts only as long as the tab is open. If i open a new tab, try to run another script or re-open Powershell ISE I have to import the module all over again.

Any ideas why this is happening?

1
  • Check your $PSModuleAutoLoadingPreference variable: about_Modules. Commented Feb 19, 2016 at 10:27

2 Answers 2

1

This is more of a work around, but you can add it to your profile.

"'Import-Module SqlPs -Verbose -Force'" > $profile

Obviously if you have a profile file from before, you dont want to do it like that, but instead open it and add it through notepad or similar.

Also note that Powershell and PowershellISE has different profiles, so you would need to add it in both if you mix.

Sign up to request clarification or add additional context in comments.

Comments

0

From my understanding, module loading is done on a per session basis. So the behavior you're seeing is what is expect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.