Get-SqlScripter
Scripts an SMO object.
Syntax
Get-SqlScripter [-smo] <Object> [[-scriptingOptions] <ScriptingOptions>] [<CommonParameters>]
Detailed Description
The Get-SqlScripter function calls the script method for an SMO object(s).
Related Commands
Parameters
Name |
Description |
Required? |
Pipeline Input |
Default Value |
smo |
|
true |
true (ByValue) |
|
scriptingOptions |
|
false |
false |
|
Input Type
Microsoft.SqlServer.Management.Smo.*
You can pipe SMO objects to Get-SqlScripter
Return Values
System.String
Get-SqlScripter returns an array System.String.
Examples
EXAMPLE 1
Get-SqlDatabase "Z002\sql2k8" "pubs" | Get-SqlTable | Get-SqlScripter
This command scripts out all user tables in the pubs database.
EXAMPLE 2
Get-SqlDatabase "Z002\sql2k8" "pubs" | Get-SqlTable -name "authors" | Get-SqlScripter
This command scripts out the authors table.
EXAMPLE 3
$scriptingOptions = New-SqlScriptingOptions
$scriptingOptions.Permissions = $true
$scriptingOptions.IncludeIfNotExists = $true
Get-SqlDatabase "Z002\sql2k8" "pubs" | Get-SqlTable | Get-SqlScripter -scriptingOptions $scriptingOptions
This command scripts out all users tables in the pubs database and passes a scriptingOptions.