View Single Post
Old 09-20-2007   #4 (permalink)
NJC


 
 

Re: Implementing SMO in Powershell

Thanks Shay and Rich for you quick replies!

Shay...
Thanks for the link but i'll already used that info to create my database.
Its about the only useful information out there on SMO in Powershell.

Rich...
Many Thanks and a huge thumbs up! The code snippet you've written works
great and given me a lot to play with

"RichS" wrote:
Quote:

> I got this to work. Obviously need to add more columns as required
>
> $null =
> [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
> $null =
> [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")
> $null = [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
> $Server = new-object Microsoft.SqlServer.Management.Smo.Server("RSSQL1")
> $db = $server.Databases["Test"]
>
> $table = New-Object Microsoft.SqlServer.Management.Smo.Table($db, "NewTable")
>
>
> $dt1 = [Microsoft.SqlServer.Management.Smo.Datatype]::Nchar(50)
> $col1 = New-Object Microsoft.SqlServer.Management.Smo.Column($table, "Name",
> $dt1)
> $col1.Collation = "Latin1_General_CI_AS"
> $col1.Nullable = $false
>
> $table.Columns.Add($col1)
> $table.Create()
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "Shay Levi" wrote:
>
Quote:

> > Try
> >
> > http://www.databasejournal.com/featu...le.php/3691566
> >
> >
> > Shay
> > http://scriptolog.blogspot.com
> >
> >
> >
Quote:

> > > Hello,
> > >
> > > I am fairly new to Powershell and certainly not to familiar with SMO,
> > > so really need some help with this problem I’ve encountered.
> > >
> > > I’m essentially trying to script the creation of a SQL Server 2005
> > > database with the applicable entities using SMO. I have successfully
> > > created a database using SMO, but not too sure on how to script the
> > > creation of new entities and add them to a particular database. I have
> > > searched high and low but can’t find any relevant information on the
> > > subject.
> > >
> > > I have found a useful add-on called PowerSMO but this can only be used
> > > for test purposes whereas I will be implementing my work into
> > > production.
> > >
> > > I guess I’ll have to use something like
> > > ‘Microsoft.SqlServer.Management.Smo.Table’ but I’m not entirely sure
> > > of the syntax or how to implement this object.
> > >
> > > If anyone can answer my question or point me in the right direction
> > > (any direction) I’d really appreciate it.
> > >
> > > Thanks,
> > >
> >
> >
> >
My System SpecsSystem Spec