Set-Acl:使用Addaudit规则时尝试执行未经授权的操作

时间:2018-04-02 16:02:11

标签: windows powershell scripting powershell-v2.0

我正在尝试运行Powershell脚本,在我的Windows 2008机器上的C:\ Windows \ security文件夹上设置审核规则。

以下是剧本:

$FileDirList = ("C:\Windows\security")

$AccountName     = New-Object System.Security.Principal.NTAccount("Everyone") 
$FileSystemRight = [System.Security.AccessControl.FileSystemRights]::FullControl
$AuditFlag       = [System.Security.AccessControl.AuditFlags]::Failure
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None

#
#write-OSPBOSbuildLog  "Applying Audit Setting"
#     

foreach ($FileDirName in $FileDirList) {   
    #write-OSPBOSbuildLog  ">>>>>  Appying audit setting to $FileDirName"

    $AuditRule = New-Object System.Security.AccessControl.FileSystemAuditRule $AccountName, $FileSystemRight, $InheritanceFlag, $PropagationFlag, $AuditFlag 

    $objACL = Get-ACL $FileDirname 

    $objACL.AddAuditRule($AuditRule)

    Set-ACL $FileDirname $objACL
} 

但我收到的错误如下所示:

Set-Acl : Attempted to perform an unauthorized operation.
At C:\IBM\File-Perm.ps1:22 char:12
+     Set-ACL <<<<  $FileDirname $objACL
    + CategoryInfo          : PermissionDenied: (C:\Windows:String) [Set-Acl], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand

请帮助我了解我需要做哪些更改?

先谢谢!!

0 个答案:

没有答案