Skip to content

Copy-DbaInstanceAudit - Throwing multiple errors, however still copies, I guess down to EXTERNAL_MONITOR and not a SQLAudit path #10113

@Ant-Green

Description

@Ant-Green

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string.
Parameter name: length"
At line:10834 char:25
+ ...                        $root = $currentAudit.Filepath.Substring(0, 3)
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException
 
Join-AdminUnc : Cannot validate argument on parameter 'filepath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:10835 char:72
+ ...                  $rootUnc = Join-AdminUnc $resolvedComputerName $root
+                                                                     ~~~~~
    + CategoryInfo          : InvalidData: (:) [Join-AdminUnc], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Join-AdminUnc
 
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:10837 char:40
+                         if ((Test-Path $rootUnc) -eq $true) {
+                                        ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
 

Type         Name                     Status     Notes
----         ----                     ------     -----
Server Audit AuditCredentialChanges   Successful      
Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string.
Parameter name: length"
At line:10834 char:25
+ ...                        $root = $currentAudit.Filepath.Substring(0, 3)
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException
 
Join-AdminUnc : Cannot validate argument on parameter 'filepath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:10835 char:72
+ ...                  $rootUnc = Join-AdminUnc $resolvedComputerName $root
+                                                                     ~~~~~
    + CategoryInfo          : InvalidData: (:) [Join-AdminUnc], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Join-AdminUnc
 
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:10837 char:40
+                         if ((Test-Path $rootUnc) -eq $true) {
+                                        ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
 
Server Audit AuditJobChanges          Successful      
Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string.
Parameter name: length"
At line:10834 char:25
+ ...                        $root = $currentAudit.Filepath.Substring(0, 3)
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException
 
Join-AdminUnc : Cannot validate argument on parameter 'filepath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:10835 char:72
+ ...                  $rootUnc = Join-AdminUnc $resolvedComputerName $root
+                                                                     ~~~~~
    + CategoryInfo          : InvalidData: (:) [Join-AdminUnc], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Join-AdminUnc
 
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:10837 char:40
+                         if ((Test-Path $rootUnc) -eq $true) {
+                                        ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
 
Server Audit AuditMSFTActivities      Successful      
Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string.
Parameter name: length"
At line:10834 char:25
+ ...                        $root = $currentAudit.Filepath.Substring(0, 3)
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException
 
Join-AdminUnc : Cannot validate argument on parameter 'filepath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:10835 char:72
+ ...                  $rootUnc = Join-AdminUnc $resolvedComputerName $root
+                                                                     ~~~~~
    + CategoryInfo          : InvalidData: (:) [Join-AdminUnc], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Join-AdminUnc
 
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:10837 char:40
+                         if ((Test-Path $rootUnc) -eq $true) {
+                                        ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
 
Server Audit AuditRestoreBackupDelete Successful      

Steps to Reproduce

CREATE SERVER AUDIT [AuditRestoreBackupDelete]
TO EXTERNAL_MONITOR WITH (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE, AUDIT_GUID = 'bc1e31a0-7495-4656-9035-914fd28d5284', OPERATOR_AUDIT = OFF);
GO
CREATE SERVER AUDIT SPECIFICATION [AuditSpecRestoreBackupDelete]
FOR SERVER AUDIT [AuditRestoreBackupDelete]
ADD (BACKUP_RESTORE_GROUP),
ADD (DATABASE_CHANGE_GROUP)
WITH (STATE = ON)
GO
ALTER SERVER AUDIT [AuditRestoreBackupDelete] WITH (STATE = ON)
GO


$SourceServer = "SourceInstance"
$DestinationServer = "DestinationInstance"
$SqlUsername = "SQLUser"
$SqlPassword = "SQLPass"

$Credential = New-Object System.Management.Automation.PSCredential($SqlUsername, (ConvertTo-SecureString $SqlPassword -AsPlainText -Force))

Copy-DbaInstanceAudit -Source $SourceServer -Destination $DestinationServer -SourceSqlCredential $Credential -DestinationSqlCredential $Credential -Force

Please confirm that you are running the most recent version of dbatools

Yes 2.7.22

Other details or mentions

Ran ISE both as a normal user and as an admin, same error when attempting to copy the audits.

My guess is this is something to do with not using a SQLAudit path, but using Azure Log Workspaces (EXTERNAL MONITOR) so it's throwing the error.

What PowerShell host was used when producing this error

Windows PowerShell ISE (powershell_ise.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.8276
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.8276
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Azure SQL Managed Instance - SQL 2022

.NET Framework Version

.NET Framework 4.8.4795.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions