join the MSSQLTips community

MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

 
Generating SQL Scripts using Windows PowerShell - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

Generating SQL Scripts using Windows PowerShell

Last post 03-03-2010 3:08 PM by samshah101. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 09-22-2009 12:30 AM

    Generating SQL Scripts using Windows PowerShell

    This post is related to this tip: Generating SQL Scripts using Windows PowerShell

    http://www.mssqltips.com/tip.asp?tip=1842

  • 09-22-2009 7:21 AM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    I tried the script at the end and got this error: Multiple ambiguous overloads found for "Script" and the argument count: "1". At C:\Documents and Settings\riyer\My Documents\scripts\scripter.ps1:22 char:13 + $scrp.Script <<<
  • 09-22-2009 8:40 AM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

     I copied the exact same script and it worked perfectly fine. Check that you have the Northwind database created in your SQL Server instance. You also need to check your instance name in Line 4 and make sure that you have the correct folders and path in lines 7 and 21

  • 10-02-2009 12:03 PM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    Not practical. Spending the time to learn Power Script, you could have had it done in T-SQL. This script has no particular rules. It is not practical to script for a new task. You will be spending weeks to find out how to write something and without a debugger to help.

  • 10-17-2009 4:02 PM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    I totally agree with you. Learning Windows PowerShell is not as easy as it seems as you have to deal with a ton of .NET-related objects. Which is why MSSQLTips is here to make the learning process a bit easier than doing it on your own. But it's like learning how to walk - it's hard to start but you have to. Microsoft is defining the next wave of server products to include manageability using PowerShell (they've already started out in Exchange 2007) so learning PowerShell will enable any administrator to write scripts that can manage just about any Microsoft server product, not just SQL Server. And since SQL Server 2005 and higher has been built on top of the .NET Framework with SMO, you can take advantage of the exposed APIs to administer SQL Server by using PowerShell

    BTW, if you are looking for a nice IDE for writing PowerShell scripts, check out PowerGUI from Quest Software. It's a free IDE and script editor for Windows PowerShell that enables you to do stuff such as debug your scripts. 

    http://www.powergui.org/index.jspa

  • 01-27-2010 1:14 AM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    hi

    what did you do to get over this.  i am getting the same error and cant find a solution.  any help would be very handy.

    Multiple ambiguous overloads found for "Script" and the argument count: "1".

  • 01-27-2010 2:39 PM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    Can you post your entire script?

  • 02-26-2010 4:30 PM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    i am also receiving the ambiguous error. can someone take a look?

     windows server 2008 R2
    SQL Server 2008 Sp1
    Powershell 2.0

    it's the last line that gets the error:


    PS C:\> [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
    PS C:\> $s = new-object ('Microsoft.SqlServer.Management.Smo.Server') "LOCALHOST"
    PS C:\> $dbs=$s.Databases
    PS C:\> $dbs["AdventureWorks"].Script() | Out-File C:\temp\myscript.SQL
    PS C:\> $scrp = new-object ('Microsoft.SqlServer.Management.Smo.Scripter') ($s)
    PS C:\> $scrp.Options.AppendToFile = $True
    PS C:\> $scrp.Options.ClusteredIndexes = $True
    PS C:\> $scrp.Options.DriAll = $True
    PS C:\> $scrp.Options.ScriptDrops = $True
    PS C:\> $scrp.Options.IncludeHeaders = $True
    PS C:\> $scrp.Options.ToFileOnly = $True
    PS C:\> $scrp.Options.Indexes = $True
    PS C:\> $scrp.Options.WithDependencies = $True
    PS C:\> $scrp.Options.FileName = "C:\temp\myscript.SQL"
    PS C:\> $scrp.Script($dbs["AdventureWorks"].Tables)
    Multiple ambiguous overloads found for "Script" and the argument count: "1".
    At line:1 char:13
    + $scrp.Script <<<< ($dbs["AdventureWorks"].Tables)
        + CategoryInfo          : NotSpecified: (:) [, MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest

     

     

    thanks in advance

  • 03-03-2010 3:08 PM In reply to

    Re: Generating SQL Scripts using Windows PowerShell

    has anyone found a cure to this.

     

Page 1 of 1 (9 items)