2014-12-04 22 views
2

我是一名通用的powershell /腳本/生活新手,但最終我遇到了值得尋求幫助的問題: 我在環境中使用了各種Windows本地化 - 英語,芬蘭語和俄語在當前的環境中,但有可能有其他斯堪的納維亞/歐洲本地化。我需要將經過身份驗證的用戶添加到管理員組。我可以用英文編寫腳本:通過SID以多種語言向本地組添加成員

NET LOCALGROUP Administrators "Authenticated Users" /add, 

但我不會知道所有本地化的名稱。例如,在俄語中,它將是「管理員」和「Proshedshie Proverku」。在cyrilic中,我沒有那麼強大。 當然,我知道SIDs - 管理員的S-1-5-32-544和認證用戶的S-1-5-11。然而,運行

NET LOCALGROUP S-1-5-32-544 S-1-5-11 /add returns error that group doesn't exist. Ok, so I found a script to check it - 

$objUser = New-Object System.Security.Principal.NTAccount("kenmyer") 

$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) 

$strSID.Value 

這返回期望值,迄今爲止好。然後我試圖仔細檢查它-by運行線路從SID得到的名字 -

$Admin = (Get-WMIObject -Class Win32_Group -Filter "LocalAccount=True and SID='S-1-5-32-544'").Name 

$Auth = (Get-WMIObject -Class Win32_Group -Filter "LocalAccount=True and SID='S-1-5-11'").Name 

而且$Admin = Administratori(因爲它應該是),而$Auth =什麼。沒有名字。這就是我停止的地方。我在英語環境中也嘗試過這種方式 - 仍然沒有「這樣的羣體」信息。運行我寫的第一個命令,用這兩個英文名字 - 完全正常工作。

任何想法?

UPD: 也許我不能正確解釋什麼,我試圖做的,所以讓腳本來說話:

#Task: to add "Authenticated users" to "Administrators" group in any languange OS. 
$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") 
$objgroup = $objSID.Translate([System.Security.Principal.NTAccount]) 
$objgroupnameAdm = ($objgroup.Value).Split("\")[1] 

$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-11") 
$objgroup = $objSID.Translate([System.Security.Principal.NTAccount]) 
$objgroupnameAuth = ($objgroup.Value).Split("\")[1] 

#Administratörer 
#Autentiserade användare 

net localgroup $objgroupnameAdm $objgroupnameAuth /add 

我現在試試這個有關瑞典的Win7。所以結果是:

net.exe : Syntaxen för kommandot är: 
At line:13 char:4 
+ net <<<< localgroup $objgroupnameAdm $objgroupnameAuth /add 
    + CategoryInfo   : NotSpecified: (Syntaxen för kommandot är::String) [], RemoteException 
    + FullyQualifiedErrorId : NativeCommandError 

我試過把也是在$objgroupnameAuth引號,因爲它包含兩個詞,但給出相同的結果。將字符串定義爲字符串 - 無變化,並用實際值替換$objGroupNameAdm - 無變化。

如果我不能用英文Windows做,我會認爲它在功能上是不可能的。

+0

你可能想也嘗試在安全SE這個問題(http://security.stackexchange.com/) – neontapir 2014-12-04 15:25:13

+0

這個答案應該給你什麼,你需要: http://stackoverflow.com/questions/21288220/get-all-local-members-and-groups-together-together – 2014-12-05 01:20:30

+0

@EricLongstreet,那個鏈接讓我更進了一步 - 我可以用任何語言獲取這兩個名字。但是,當我嘗試將認證用戶添加到管理員組時,仍然出現「無法完成,因爲用戶不存在」的錯誤。腳本仍然可以在英文版Windows中運行 - 可以通過[link](http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/25/use-powershell-html)與'net localgroup'或'[ADSI] to-add-local-users-to-local-groups.aspx)。 – 2014-12-05 10:52:58

回答

0

問題很簡單,一旦問得正確,答案就在這裏找到:Microsoft Supprt: NET /ADD command。 如果NET限制爲20個字符,並且「Autentiseradeanvändare」爲24個字符,則不應起作用。解決方法是在同一個鏈接中找到。

0

SID S-1-5-11用於Authenticated UsersWell known SIDs)。這是一個無法修改的BUILTIN組。像這樣的其他組是EveryoneAnonymous

這種類型的組不存在「物理」意義或詞,即沒有對象創建本地SAM或Active Directory中。

它們完全由Windows生成和管理。

您在會話中收到SID,具體取決於您連接和/或登錄的方式。

因此,製作WMI Win32_Group請求或使用Get-ADGroup不會返回任何內容。

您可以調用Get-ADAccountAuthorizationGroup來查看特定身份是否爲此類組的成員。

您可以使用SID來檢索創建創建System.Security.Principal.NTAccount對象指向Authenticated Users

$auth = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-11") 
$name = $auth.Translate([System.Security.Principal.NTAccount]) 

更新: 我不能AUTH到該組中添加的$本地化名稱。看起來只有英文版纔有效。

+0

我的最終目標是將本地組「身份驗證用戶」添加到本地「管理員」組。出於實用目的,我可以添加「域用戶」,這將給出需要的結果 - 任何人都是該機器的管理員 - 但這會是安全漏洞,因爲它允許無限遠程訪問等。 – 2014-12-05 10:55:48

+0

您可以使用計算機管理應用程序控制臺)手動添加它,或者我更新了響應來檢索指向該組的對象。 – 2014-12-05 12:42:19

+0

如果這將是唯一的選擇,那麼我們會繼續這樣做,當然,但是因爲它可以用英語在PS中完成,所以我應該可以用其他語言來完成。 – 2014-12-05 13:11:06

0

我用這個方法來翻譯從SID到本地化名稱:

.SYNOPSIS 添加了「NT AUTHORITY \互動安全主體到本地計算機管理員組」

.DESCRIPTION 這個腳本使用SID轉換以接收Interactive主體和Administrators組的本地化名稱,然後使用本地化名稱將主體添加到組。

# Translate the S-1-5-32-544 (.\Administrators) SID to a group name, the name varies depending on the language version of Windows. 
$sid2 = 'S-1-5-32-544' 
$objSID2 = New-Object System.Security.Principal.SecurityIdentifier($sid2) 
$localadminsgroup = (($objSID2.Translate([System.Security.Principal.NTAccount])).Value).Split("\")[1] 

# Translate the S-1-5-4 (NT AUTHORITY\Interactive) SID to an account name, the name varies depending on the language version of Windows. 
$sid1 = 'S-1-5-4' 
$objSID1 = New-Object System.Security.Principal.SecurityIdentifier($sid1) 
$interactive = (($objSID1.Translate([System.Security.Principal.NTAccount])).Value).Split("\")[1] 

# Add the security principal name to the local administrators group. (used old style of adding group members due to compatibility reasons) 

try { 
    Write-Host "Adding security principal: $interactive to the $localadminsgroup group..." 

    $group = [ADSI]"WinNT://$env:computername/$localadminsgroup,group" 
    $ismember = "False" 

    @($group.Invoke("Members")) | ForEach-Object { 
     If ($interactive -match $_.GetType.Invoke().InvokeMember("Name", 'GetProperty', $null, $_, $null)) { 
      $ismember = "True" 
     } 
    } 

    If ($ismember -eq "True") { 
     write-host "user $interactive is already a member of $localadminsgroup" 
    } 
    Else { 
     $result = $group.Add("WinNT://NT AUTHORITY/$interactive,user") 
     write-host "user $interactive is added to $localadminsgroup" 
    } 
} 
Catch { 
    write-host $_.Exception.Message 
} 

它並不完全適合您的需要,但我相信您可以使其工作。

Regards,

Koen。