Iklan Beranda

new-object : Cannot find type [Microsoft.SqlServer.Management.Smo.Server]: verify that the assembly containing this type is loaded.

Issue : when you connect to SQl Server using  SMO in Powershell you get below error..
-------



new-object : Cannot find type [Microsoft.SqlServer.Management.Smo.Server]: verify that the assembly containing this
type is loaded.
At line:1 char:6
+ $s = new-object ('Microsoft.SqlServer.Management.Smo.Server') 'sqlnod ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand


Resolution.

To install the SqlServer module from the PowerShell Gallery, start a PowerShell session and use the following commands.


To install the SqlServer module:

   Install-Module -Name SqlServer

If there are previous versions of the SqlServer module on the computer, you may be able to use Update-Module (later in this article), or provide the -AllowClobber parameter:

   Install-Module -Name SqlServer -AllowClobber

If you are not able to run the PowerShell session as administrator, you can install for the current user:

   Install-Module -Name SqlServer -Scope CurrentUser

When updated versions of the SqlServer module are available, you can update the version using Update-Module:

   Update-Module -Name SqlServer

To view the versions of the module installed:

  Get-Module SqlServer -ListAvailable

To use a specific version of the module, you can import it with a specific version number similar to the following:

     Import-Module SqlServer -Version 21.0.17178

your final screen will be like below:



Thanks for Reading..


Post a Comment

Previous Post Next Post