< Back

Get-DbSmo

Mon Jan 13, 2020 6:25 pm

NAME Get-DbSmo



SYNOPSIS

Creates an SQL Server SMO Server object for a database engine instance.





SYNTAX

Get-DbSmo [-ServerInstance] <String> [-Credential <Object>] [-Preload] [-PreloadAg] [-RetryCount <Object>]

[-RetrySeconds <Object>] [<CommonParameters>]



Get-DbSmo [-SqlConnection] <SqlConnection> [[-ServerInstance] <String>] [-Credential <Object>] [-Raw] [-Preload]

[-PreloadAg] [-RetryCount <Object>] [-RetrySeconds <Object>] [<CommonParameters>]





DESCRIPTION

While it's easy to instantiate a connection to SQL Server SMO it has a few bugs that require extra workarounds.



* It doesn't provide a simple interface to set a timeout.

* It has a bug which prevent DefaultInitFields from being set to retrieve and cache all fields (without a specific

exception it will cause failures on some database properties).

* It can return an object even if the server is not up.

* And even then the object can silently swallow errors and return blank fields if the server is not up.



This wrapper gets around each of these faults, the last of which by connecting and disconnecting, which keeps a

connection alive in the pool, but closed so it doesn't require further management. Testing shows that this is

sufficient to cause the object to flag errors on dead servers.





PARAMETERS

-SqlConnection <SqlConnection>

A SqlConnection object.



Required? true

Position? 2

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-ServerInstance <String>

A server instance to connect to, for example ".\\SQL2016"



Required? true

Position? 2

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-Credential <Object>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Raw [<SwitchParameter>]

If you pass in a SqlConnection object by default it is used to construct a new one, this is required for SMO

to automatically

manage soft-closing the connection (as it sets a NonPooled property which cannot be modified). If you don't

care about this

behaviour this switch allows the use of the raw connection, just remember SMO won't close it.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Preload [<SwitchParameter>]

Cache all possible data in a minimum of reads.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-PreloadAg [<SwitchParameter>]

Only cache Availability Group data (otherwise this is extremely chatty).



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-RetryCount <Object>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-RetrySeconds <Object>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

A server name or a connection object.





OUTPUTS

An SMO Server object.





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$smo = Get-DbSmo . -Preload















RELATED LINKS