2014-07-24 24 views
1

我試圖將文件所有者設置爲另一個域中的SID。 此域名不可信,以下內容無效。通過PowerShell將文件所有者設置爲不受信任域中的用戶

PS > (Get-Acl .).SetOwner([System.Security.Principal.NTAccount]'TESTWORLD\barry') 
Exception calling "SetOwner" with "1" argument(s): "Some or all identity references could not be translated." 
At line:1 char:1 
+ (Get-Acl .).SetOwner([System.Security.Principal.NTAccount]'TESTWORLD\barry') 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
+ FullyQualifiedErrorId : IdentityNotMappedException 

我能夠從其他領域得到了用戶的SID像這樣:

$c = Get-Credentials TESTWORLD.INVALID\AdminUser 
$dc = Get-ADDomainController -Discover -DomainName TESTWORLD.INVALID -Service PrimaryDC | %{$_.HostName} 
$sid = Get-ADUser -Filter {Name -eq "barry"} -Server $dc -Credential $c | %{$_.SID} 

我再要將此SID是該文件的所有者。這怎麼可能?

+0

我不認爲你可以。我想不出爲什麼安全系統會允許這麼做,或者你爲什麼要這樣做。 – mjolinor

+0

@mjolinor - 我正在從另一個域中安裝資源,如下所示:「PS C:\> New-PSDrive -Name TEST -PSProvider FileSystem -Root \\ FILE01t.TESTWORLD.INVALID \ vol01 $ -Credential $ c」。然後我在TEST:\ Filename創建一個文件,然後希望將指定的憑證中的所有者更改爲TESTWORLD域中的另一個用戶 – user3872925

+0

您是否嘗試過重新編寫SDDL字符串? – mjolinor

回答

0

如果允許DCOM通信到遠程計算機,請嘗試以下操作。您需要將$ Path設置爲遠程系統的本地路徑。如果您使用備用憑據,在$ OptionalCred哈希表提供憑據值:

試試這個:

$Path = "C:\Folder" 
$OwnerSID = # SID string goes here #  
$Computer = $env:ComputerName 
$OptionalCred = @{ 
    # Don't use this running against local machine 
    #Credential = Get-Credential TESTWORLD.INVALID\AdminUser 
} 

$EscapedPath = [regex]::Escape($Path) 
$FileSecuritySetting = Get-WmiObject Win32_LogicalFileSecuritySetting -Filter "Path='$EscapedPath'" -ComputerName $Computer @OptionalCred 
$Win32SD = $FileSecuritySetting | Invoke-WmiMethod -Name GetSecurityDescriptor | select -ExpandProperty Descriptor 

$NewOwner = ([wmiclass]"Win32_Trustee").PSBase.CreateInstance() 
$NewOwner.SIDString = $OwnerSID 
$Win32SD.Owner = $NewOwner 

Invoke-WmiMethod -Path $FileSecuritySetting.__PATH -Name SetSecurityDescriptor -ArgumentList $Win32SD @OptionalCred 
+0

This Works - Great! – user3872925

相關問題