0

I'm trying to run Invoke-Sqlcmd on a computer and got the following error.

PS C:\> Invoke-Sqlcmd -server server1 'select 1 a'
Invoke-Sqlcmd : The 'Invoke-Sqlcmd' command was found in the module 'SqlServer', but the module could not be loaded.
For more information, run 'Import-Module SqlServer'.
At line:1 char:1
+ Invoke-Sqlcmd -server server1 'select 1 a'
+ ~~~~~~~~~~~~~
 + CategoryInfo : ObjectNotFound: (Invoke-Sqlcmd:String) [], CommandNotFoundException
 + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

However, Import-Module failed?

PS C:\> Import-Module SqlServer

Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.SqlServer.Management.Smo.Agent.Job": The member LastRunDuration is already present.
Error in TypeData "Microsoft.SqlServer.Management.Smo.Agent.JobStep": The member LastRunDurationAsTimeSpan is already present.
Error in TypeData "Microsoft.SqlServer.Management.Smo.NamedSmoObject": The member DefaultKeyPropertySet is already present.
Error in TypeData "Microsoft.SqlServer.Management.Smo.NamedSmoObject": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.SqlServer.Management.Smo.NamedSmoObject": The member DefaultDisplayProperty is already present.
At line:1 char:1
+ Import-Module SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

marc_s
760k185 gold badges1.4k silver badges1.5k bronze badges
asked May 24, 2018 at 19:09
5
  • I installed sql server management studio 2017 on the computer Commented May 24, 2018 at 20:13
  • It looks like this is a common issue if you have the previous SQLPS module installed. SQLPS came with pre-2016 (but post-2008) versions of sql server. Commented May 24, 2018 at 20:16
  • @TheIncorrigible1 I don't know. I guess it comes with SSMS? Commented May 24, 2018 at 20:41
  • Try import-module sqlps and report back Commented May 24, 2018 at 20:43
  • 1
    @TheIncorrigible1 Found out Set-ExecutionPolicy -ExecutionPolicy RemoteSigned resolves the problem. Commented May 24, 2018 at 20:47

1 Answer 1

3

Found out that Set-ExecutionPolicy -ExecutionPolicy RemoteSigned resolved the problem.

answered May 24, 2018 at 20:47
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.