Partager via


Méthode 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.

Espace de noms :  Microsoft.SqlServer.Management.Smo
Assembly :  Microsoft.SqlServer.Smo (en Microsoft.SqlServer.Smo.dll)

Syntaxe

'Déclaration
Public Function Script As StringCollection
'Utilisation
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

Valeur de retour

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

Implémente

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

Exemples

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
}