Skip to content

New SqlDscAudit

dscbot edited this page Mar 3, 2024 · 2 revisions

New-SqlDscAudit

SYNOPSIS

Creates a server audit.

SYNTAX

FileWithSizeAndMaxRolloverFiles

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -Path <String>
 -MaximumFileSize <UInt32> -MaximumFileSizeUnit <String> -MaximumRolloverFiles <UInt32>
 [-WhatIf] [-Confirm] [<CommonParameters>]

FileWithSizeAndMaxFiles

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -Path <String>
 -MaximumFileSize <UInt32> -MaximumFileSizeUnit <String> -MaximumFiles <UInt32> [-ReserveDiskSpace]
 [-WhatIf] [-Confirm] [<CommonParameters>]

FileWithMaxRolloverFiles

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -Path <String>
 -MaximumRolloverFiles <UInt32> [-WhatIf] [-Confirm] [<CommonParameters>]

FileWithMaxFiles

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -Path <String>
 -MaximumFiles <UInt32> [-ReserveDiskSpace] [-WhatIf] [-Confirm]
 [<CommonParameters>]

FileWithSize

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -Path <String>
 -MaximumFileSize <UInt32> -MaximumFileSizeUnit <String> [-WhatIf]
 [-Confirm] [<CommonParameters>]

File

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -Path <String>
 [-WhatIf] [-Confirm] [<CommonParameters>]

Log

New-SqlDscAudit -ServerObject <Server> -Name <String> [-AuditFilter <String>] [-OnFailure <String>]
 [-QueueDelay <UInt32>] [-AuditGuid <String>] [-Force] [-Refresh] [-PassThru] -LogType <String>
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command creates a server audit on a SQL Server Database Engine instance.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$sqlServerObject | New-SqlDscAudit -Name 'MyFileAudit' -Path 'E:\auditFolder'

Create a new file audit named MyFileAudit.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$sqlServerObject | New-SqlDscAudit -Name 'MyAppLogAudit' -LogType 'ApplicationLog'

Create a new application log audit named MyAppLogAudit.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$sqlServerObject | New-SqlDscAudit -Name 'MyFileAudit' -Path 'E:\auditFolder' -PassThru

Create a new file audit named MyFileAudit and returns the Audit object.

PARAMETERS

-AuditFilter

Specifies the filter that should be used on the audit. See predicate expression how to write the syntax for the filter.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-AuditGuid

Specifies the GUID found in the mirrored database. To support scenarios such as database mirroring an audit needs a specific GUID.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Force

Specifies that the audit should be created without any confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-LogType

Specifies the log location where the audit should write to. This can be SecurityLog or ApplicationLog.

Type: String
Parameter Sets: Log
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-MaximumFiles

Specifies the number of files on disk.

Type: UInt32
Parameter Sets: FileWithSizeAndMaxFiles, FileWithMaxFiles
Aliases:

Required: True
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-MaximumFileSize

Specifies the maximum file size in units by parameter MaximumFileSizeUnit.

Type: UInt32
Parameter Sets: FileWithSizeAndMaxRolloverFiles, FileWithSizeAndMaxFiles, FileWithSize
Aliases:

Required: True
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-MaximumFileSizeUnit

Specifies the unit that is used for the file size. This can be set to Megabyte, Gigabyte, or Terabyte.

Type: String
Parameter Sets: FileWithSizeAndMaxRolloverFiles, FileWithSizeAndMaxFiles, FileWithSize
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-MaximumRolloverFiles

Specifies the amount of files on disk before SQL Server starts reusing the files. If not specified then it is set to unlimited.

Type: UInt32
Parameter Sets: FileWithSizeAndMaxRolloverFiles, FileWithMaxRolloverFiles
Aliases:

Required: True
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name of the server audit to be added.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-OnFailure

Specifies what should happen when writing events to the store fails. This can be 'Continue', 'FailOperation', or 'Shutdown'.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-PassThru

If specified the created audit object will be returned.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Path

Specifies the location where te log files wil be placed.

Type: String
Parameter Sets: FileWithSizeAndMaxRolloverFiles, FileWithSizeAndMaxFiles, FileWithMaxRolloverFiles, FileWithMaxFiles, FileWithSize, File
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-QueueDelay

Specifies the maximum delay before a event is written to the store. When set to low this could impact server performance. When set to high events could be missing when a server crashes.

Type: UInt32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-Refresh

Specifies that the ServerObject's audits should be refreshed before creating the audit object. This is helpful when audits could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large amount of audits it might be better to make sure the ServerObject is recent enough.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ReserveDiskSpace

Specifies if the needed file space should be reserved. To use this parameter the parameter MaximumFiles must also be used.

Type: SwitchParameter
Parameter Sets: FileWithSizeAndMaxFiles, FileWithMaxFiles
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

[Microsoft.SqlServer.Management.Smo.Audit] is passing parameter PassThru,

otherwise none.

NOTES

This command has the confirm impact level set to medium since an audit is created but by default is is not enabled.

See the SQL Server documentation for more information for the possible parameter values to pass to this command: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-server-audit-transact-sql

RELATED LINKS

Home

General

Commands

Clone this wiki locally