Compartilhar via


Método Script

Generates a Transact-SQL script that can be used to re-create the instance of SQL Server affinity settings as specified in the AffinityInfo object.

Namespace:  Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (em Microsoft.SqlServer.Smo.dll)

Sintaxe

'Declaração
Public Function Script As StringCollection
'Uso
Dim instance As AffinityInfo
Dim returnValue As StringCollection

returnValue = instance.Script()
public StringCollection Script()
public:
virtual StringCollection^ Script() sealed
abstract Script : unit -> StringCollection 
override Script : unit -> StringCollection 
public final function Script() : StringCollection

Valor de retorno

Tipo: System.Collections.Specialized. . :: . .StringCollection
A StringCollection system object value that contains a list of Transact-SQL command batch statements that defines the AffinityInfo object.

Implementa

IScriptable. . :: . .Script() () () ()

Exemplos

This example shows you how to display the Transact-SQL statements needed to set an Instance of SQL Server to the current values stored in a AffinityInfo object.

using System;
using System.Collections.Specialized;
using Microsoft.SqlServer.Management.Smo;

namespace samples
{
    class Program
    {
        static void Main(string[] args)
        {
            Server dbServer = new Server("(local)");

            dbServer.Refresh();
            StringCollection s = dbServer.AffinityInfo.Script();
            foreach (string sv in s)
                Console.WriteLine(sv);
        }
    }
}

Powershell

#Create the server. 
$dbServer = new-Object Microsoft.SqlServer.Smo.Server("(local)")
$dbServer.Refresh()

$s = New-Object System.Collections.Specialized.StringCollection()
$s = $dbServer.AffinityInfo.Script()

Foreach ($sv in $s)
{
   Write-Host $sv
}