2014-12-04 24 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。