通过powershell创建审核失败,返回“0”;SetParent失败";

通过powershell创建审核失败,返回“0”;SetParent失败";,powershell,sql-server-2008-r2,audit,Powershell,Sql Server 2008 R2,Audit,我正在尝试使用以下PowerShell脚本在WinServer 2008 R2上创建新的服务器审核 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null $server = "SM1111" #change to desired instance $instance = "S111" $auditName = "$instance"+"TestAudit" $auditDi

我正在尝试使用以下PowerShell脚本在WinServer 2008 R2上创建新的服务器审核

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null 
$server = "SM1111" #change to desired instance
$instance = "S111"
$auditName = "$instance"+"TestAudit"
$auditDir = 'F:\Microsoft SQL Server\'+$instance+'AuditTestLogsNew\'
$srv = new-Object ('Microsoft.SqlServer.Management.Smo.Server') -argumentlist $instance

$newAudit = New-Object Microsoft.SqlServer.Management.Smo.Audit($srv, "$auditName")
$newAudit.DestinationType = [Microsoft.SqlServer.Management.Smo.AuditDestinationType]::File
$newAudit.FilePath = $auditDir
$newAudit.MaximumRolloverFiles = 10
$newAudit.MaximumFileSize = 100
$newAudit.QueueDelay = 1000
$newAudit.Create()
$newAudit.Enable()
但是,以下行始终失败:

$newAudit = New-Object Microsoft.SqlServer.Management.Smo.Audit($srv, "$auditName")
我收到以下错误消息:

New-Object : Exception calling ".ctor" with "2" argument(s): "SetParent failed for Audit 'S111TestAudit'. "
At MYFOLDER\Documents\Auditing_Test\CreateAudit.ps1:9 char:13
+ $newAudit = New-Object Microsoft.SqlServer.Management.Smo.Audit($srv, "$auditNam ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
我已经在谷歌上搜索了很多次,但仍然没有找到任何可能解决问题的方法,因为我不太明白是什么引起了这个错误

我有完全的管理员权限


任何帮助都将不胜感激

缺少实例的服务器名称。变量
$srv
未指向实际的服务器实例

$server = "SM1111" #change to desired instance     <- This isn't doing anything
$instance = "S111"
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server -argumentlist "$server\$instance"
$server=“SM1111”#更改为所需实例