After you have navigated to a node in a Database Engine provider path, you can perform work or retrieve information by using the methods and properties from the
Database Engine management object associated with the node.
Note
There are two SQL Server PowerShell modules; SqlServer and SQLPS.
The SqlServer module is the current PowerShell module to use.
The SQLPS module is included with the SQL Server installation (for backward compatibility) but is no longer updated.
The SqlServer module contains updated versions of the cmdlets in SQLPS and includes new cmdlets to support the latest SQL features.
After you navigate to a node in a Database Engine provider path, you can perform two types of actions:
You can run Windows PowerShell cmdlets that operate on nodes, such as Rename-Item.
You can call the methods from the associated SQL Server management object model, such as SMO. For example, if you navigate to the Databases node in a path, you can use the methods and properties of the <xref:Microsoft.SqlServer.Management.Smo.Database> class.
The SQL Server provider is used to manage the objects in an instance of the Database Engine. It is not used to work with the data in databases. If you have navigated to a table or view, you cannot use the provider to select, insert, update, or delete data. Use the Invoke-Sqlcmd cmdlet to query or change data in tables and views from the Windows PowerShell environment. For more information, see Invoke-Sqlcmd.
List Methods and Properties
Listing Methods and Properties
To view the methods and properties available for specific objects or object classes, use the Get-Member cmdlet.
Example: Listing methods and properties
This example sets a Windows PowerShell variable to the SMO <xref:Microsoft.SqlServer.Management.Smo.Database> class and lists the methods and properties:
To perform work on objects from a Database Engine provider path, you can use SMO methods and properties.
Example: Using methods and properties
This example uses the SMO Schema property to get a list of the tables from the Sales schema in AdventureWorks2022:
PowerShell
Set-Location SQLSERVER:\SQL\localhost\DEFAULT\Databases\AdventureWorks2022\Tables
Get-ChildItem | where {$_.Schema -eq"Sales"}
This example uses the SMO Script method to generate a script that contains the CREATE VIEW statements you must have to re-create the views in AdventureWorks2022:
This learning path explains two technologies: PowerShell providers and PowerShell drives, which let you work with many forms of storage by using the commands and techniques that you use to manage the file system.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Official product documentation for SQL Server PowerShell. SQL Server PowerShell is a collection of modules for managing SQL Server resources from PowerShell.
Learn about the SQL Server provider for Windows PowerShell, which provides access to SQL Server objects by means of paths similar to file system paths.
Learn about Query Expressions, which enumerate one or more objects in an object model hierarchy, and about Uniform Resource names (URNs), which uniquely identify a single object.
Learn about the paths that Windows PowerShell providers use to expose data hierarchies, and about the need to encode certain characters not supported by PowerShell in these paths.