Freigeben über


Script-Methode

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 (in Microsoft.SqlServer.Smo.dll)

Syntax

'Declaration
Public Function Script As StringCollection
'Usage
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

Rückgabewert

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

Implementiert

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

Beispiele

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
}