Export (0) Print
Expand All

Audit.Rename Method

Changes the name of the audit to the specified string.

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

public void Rename(
	string newname
)

Parameters

newname
Type: String
A string object specifying the new name of the audit.

Implements

IRenamableRename(String)

The new audit name must be unique. Attempting to set the audit name to the same name as an existing audit will result in a FailedOperationException.

The following code example demonstrates how to rename an audit.

C#

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

namespace samples
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create the audit
            Server dbServer = new Server("(local)");
            Audit dbAudit = new Audit(dbServer, "Test Audit");
            dbAudit.DestinationType = AuditDestinationType.File;
            dbAudit.FilePath = "C:\\AuditDirectory";
            dbAudit.Create();

            //Rename the audit and display the new name on the console
            dbAudit.Rename("New Test Audit Name");
            Console.WriteLine(dbAudit.Name);
        }
    }
}

Powershell

#Create the audit 
$dbServer = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$dbAudit = New-Object Microsoft.SqlServer.Management.Smo.Audit($dbServer, "Test Audit")
$dbAudit.DestinationType = [Microsoft.SqlServer.Management.Smo.AuditDestinationType]'File'
$dbAudit.FilePath = "C:\AuditDirectory"
$dbAudit.Create()

#Rename the audit and display the new name
$dbAudit.Rename("New Test Audit name")
Write-Host $dbAudit.Name

Community Additions

ADD
Show:
© 2014 Microsoft