Server.Audits Server.Audits Server.Audits Property

Definition

Represents a collection of Audit objects. Each Audit object represents an audit log defined on the instance of SQL Server.

public:
 property Microsoft::SqlServer::Management::Smo::AuditCollection ^ Audits { Microsoft::SqlServer::Management::Smo::AuditCollection ^ get(); };
[Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcObject(Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerRelationship.ObjectContainer, Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerCardinality.ZeroToAny, typeof(Microsoft.SqlServer.Management.Smo.Audit))]
public Microsoft.SqlServer.Management.Smo.AuditCollection Audits { get; }
Public ReadOnly Property Audits As AuditCollection
Property Value

A AuditCollection object that represents all the audit logs defined on the instance of SQL Server.

Examples

C#

//Connect to the local server and create audits  
Server srv = new Server("(local)");  
testAudit1 = new Audit(srv, "First Test Audit");  
testAudit1.DestinationType = AuditDestinationType.File;  
testAudit1.FilePath = "C:\AuditDirectory";  
testAudit1.Create();  
testAudit2 = new Audit(srv, "Second Test Audit");  
testAudit2.DestinationType = AuditDestinatinoType.File;  
testAudit2.FilePath = "C:\AuditDirectory";  
testAudit2.Create()  

//Display the populated audit property  
foreach (Audit a in srv.Audits)  
{  
   Console.WriteLine(a.Name);  
}  

PowerShell

#Connect to the local server and create audits  
$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$testAudit1 = new-object Microsoft.SqlServer.Management.Smo.Audit($srv, "First Test Audit")  
$testAudit1.DestinationType = [Microsoft.SqlServer.Management.Smo.AuditDestinationType]::File  
$testAudit1.FilePath = "C:\AuditDirectory"  
$testAudit2 = new-object Microsoft.SqlServer.Management.Smo.Audit($srv, "Second Test Audit")  
$testAudit2.FilePath = "C:\AuditDirectory"  
$testAudit2.DestinationType = [Microsoft.SqlServer.Management.Smo.AuditDestinationType]::File  
$testAudit1.Create()  
$testAudit2.Create()  

#Display the populated audit property  
foreach ($a in $srv.Audits)  
{  
   Write-Host $a.Name  
}  

Applies to