我是一名通用的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