-
Notifications
You must be signed in to change notification settings - Fork 1
/
Script-Object.ps1
15 lines (14 loc) · 2.27 KB
/
Script-Object.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
param(
[Parameter(Mandatory=$true, HelpMessage='The name of the database object we wish to script')]
[string] $ObjectName,
[string] $Path = "$($ObjectName).sql",
[string] $ConnectionString = 'Data Source=.\sqlexpress2k8R2;Initial Catalog=master;Integrated Security=SSPI;',
[string] $AtlantisSchemaEngineBaseDir = 'F:\src\Atlantis.SchemaEngine\' # Adjust for your environment
);
Add-Type -Path "$($AtlantisSchemaEngineBaseDir)\Atlantis.SchemaEngine\bin\Debug\Atlantis.SchemaEngine.dll"
$schemaReader = [Atlantis.SchemaEngine.Container.SQLServer.SQLServerSchemaReaderFactory]::GetSpecificSQLServerSchemaReader($ConnectionString, [Atlantis.SchemaEngine.Enumerations.ContainerMode]::Navigation)
$dbObjects = $schemaReader.ReadObjects() | Where-Object { $_.ObjectName,$_.ObjectDesriptiveName,$_.ObjectQualifiedName -contains $ObjectName };
if ($dbObjects -eq $null) {
Throw New-Object System.ArgumentException "Object `"$($ObjectName)`" not found.",'-ObjectName';
}
$dbObjects.Script([Atlantis.SchemaEngine.Enumerations.ScriptGenerationType]::Create, (New-Object Atlantis.SchemaEngine.Configuration.GenerationOptions)).Scripts