About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

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..