2016-11-30 29 views
1

我有一個PowerShell函數,它將啓用對Perflogs文件夾的審計。該功能在英語安裝語言的Windows PC上運行良好。但是當我在丹麥語版本上使用它時,它會失敗,因爲「丹麥語」安裝時不會退出「Everyone」。在丹麥安裝「每個人」被稱爲「全部」Powershell函數中的SID

所以不是每個人使用的話,我想用的SID「S-1-1-0」

S-1-1-0 =所有人/世界link

但由於某種原因,這也行不通。有沒有人有這方面的線索,爲什麼我不能這樣做?

function AddAuditToFile { 
param 
(
    [Parameter(Mandatory=$true)] 
    [string]$path 
) 

Get-Acl $path -Audit | Format-List Path,AuditToString | Out-File -FilePath 'file_before.txt' -Width 200 -Append 
$File_ACL = Get-Acl $path 
$AccessRule = New-Object System.Security.AccessControl.FileSystemAuditRule("S-1-1-0","CreateFiles,Modify,AppendData」,"none","none",」Success") 
$File_ACL.AddAuditRule($AccessRule) 
$File_ACL | Set-Acl $path 
Get-Acl $path -Audit | Format-List Path,AuditToString | Out-File -FilePath 'file_after.txt' -Width 200 -Append} 

我這樣調用該函數:

AddAuditToFile "C:\Perflogs" 
+0

您是否在嘗試使用SID時收到任何錯誤消息,或者看起來完全沒有做出任何更改? –

+2

''S-1-1-0「' - >'(New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType] :: WorldSid),$ null)' – PetSerAl

+0

我得到一個錯誤。並且腳本dosnt繼續。 D:不能記住錯誤。 –

回答

1

使用SecurityIdentifier類翻譯的SID:

$everyoneSid= New-Object System.Security.Principal.SecurityIdentifier "S-1-1-0" 
$everyoneSidName= $everyoneSid.Translate([System.Security.Principal.NTAccount]) 
$everyoneSidName.Value 

這將輸出取決於實際的機器上的實際所有人組名。

+0

是的,這也將解決它。感謝您的回答 –

0

Spiceworks的Gungnir找到了解決方案。

我不得不翻譯SID,使一個變量,然後使用該變量

$ AccountSID =新物體-TypeName System.Security.Principal.SecurityIdentifier -ArgumentList「S-1-1-0 '

$帳戶名= $ AccountSID.Translate([System.Security.Principal.NTAccount])。值

$ AccessRule =新物體System.Security.AccessControl.FileSystemAuditRule -ArgumentList($帳戶名,' CreateFiles ,修改,附加數據','無','無','成功')