Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell从拒绝本地登录策略获取用户_Powershell - Fatal编程技术网

PowerShell从拒绝本地登录策略获取用户

PowerShell从拒绝本地登录策略获取用户,powershell,Powershell,是否可以使用PowerShell v2接收“拒绝本地登录”策略中存在的用户?我认为有了Get GPO是可能的,但我不知道怎么做 获取GPO: 拒绝本地登录:不是很优雅,但应该可以: 导出GPO(路径必须已存在): 找到文件GptTmpl.inf,并从其内容中选择具有所需权限的行: Get-ChildItem 'C:\some\folder' -Filter 'gpttmpl.inf' -Recurse | Get-Content | Where-Object { $_ -like '

是否可以使用PowerShell v2接收“拒绝本地登录”策略中存在的用户?我认为有了Get GPO是可能的,但我不知道怎么做

获取GPO:


拒绝本地登录:

不是很优雅,但应该可以:

  • 导出GPO(路径必须已存在):

  • 找到文件
    GptTmpl.inf
    ,并从其内容中选择具有所需权限的行:

    Get-ChildItem 'C:\some\folder' -Filter 'gpttmpl.inf' -Recurse |
      Get-Content |
      Where-Object { $_ -like 'SeDenyInteractiveLogonRight*' }
    
  • 从线路中提取SID:

    ... -replace '^.* = ' -replace '\*' -split ','
    
  • 将SID转换回用户名/组名:

    $acct = [wmi]"Win32_Sid.SID='$sid'"
    '{0}\{1}' -f $acct.ReferencedDomainName, $acct.AccountName
    
  • 清理一下


    • 这似乎起到了作用

      $ad_deny_logon = `
          (Get-WmiObject -Class RSOP_UserPrivilegeRight -Namespace root\rsop\computer | `
              Where-Object{
                  $_.UserRight -eq "SeDenyInteractiveLogonRight" -and 
                  $_.precedence -eq 1
              }
          ) | `
              sort -Unique | `
                  Select-Object @{Name="User & Groups";Expression={$_.AccountList}}, @{Name="Computer name";Expression={$_.PSComputerName}}
      

      您正在将Name属性用于Export GPO,但该属性是否与Get GPO中的相同?因为如果我使用Get-GPO-all返回所有策略,它将只返回两个策略默认域策略和默认域控制器策略。因此,输出中不存在拒绝本地登录策略。这两个策略都有由Microsoft.GroupPolicy.UserConfiguration值表示的用户值。是,名称是名称。如果没有得到结果,可能是设置没有定义,或者是某个地方出错。另外,权限只能通过机器策略分配,不能通过用户策略分配。啊哈,谢谢。我将不得不与其他人核实这是否可行,如果可行,我将在今天晚些时候将其标记为答案。
      $ad_deny_logon = `
          (Get-WmiObject -Class RSOP_UserPrivilegeRight -Namespace root\rsop\computer | `
              Where-Object{
                  $_.UserRight -eq "SeDenyInteractiveLogonRight" -and 
                  $_.precedence -eq 1
              }
          ) | `
              sort -Unique | `
                  Select-Object @{Name="User & Groups";Expression={$_.AccountList}}, @{Name="Computer name";Expression={$_.PSComputerName}}