我是一名通用的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做,我會認爲它在功能上是不可能的。
你可能想也嘗試在安全SE這個問題(http://security.stackexchange.com/) – neontapir 2014-12-04 15:25:13
這個答案應該給你什麼,你需要: http://stackoverflow.com/questions/21288220/get-all-local-members-and-groups-together-together – 2014-12-05 01:20:30
@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