zoukankan      html  css  js  c++  java
  • powershell:限制计算机可登录的用户名

    $ScriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent 
    $CarbdllPath = "$ScriptDirCarbon.dll"
    [void][System.Reflection.Assembly]::LoadFile( $CarbdllPath )
    $LimtlocalUserGroup = "LogonUser"
    $DenylocalUserGroup = "Users"
    $Privilege = "SeInteractiveLogonRight"
    $LocalGroups = Get-WMIObject win32_group -filter "LocalAccount='True'"
    $GetAdministrsUsers = Net localgroup Administrators | ?{$_} | select -Skip 4
    $GetUsers = Net localgroup Users | ?{$_} | select -Skip 4
    $AllLimtUser = $GetAdministrsUsers + $GetUsers |Sort-Object -Unique | ?{$_ -like "AAC*" -and $_ -notlike "*Users*" -and $_ -notlike "*admin*" }
    if ($LocalGroups.name -notcontains $LimtlocalUserGroup )
            { net localgroup $LimtlocalUserGroup /add | Out-Null 
              foreach ( $User in $AllLimtUser )
                {
                 net localgroup $LimtlocalUserGroup $user /add | out-null 
                }
            }
            else 
            {
              $GetLogonUser = Net localgroup $LimtlocalUserGroup | ?{$_ -like "AAC*"}
              foreach ($user in $AllLimtUser) 
                {
                 if ($GetLogonUser -notcontains $user)
                    {
                     net localgroup $LimtlocalUserGroup $User /add | Out-Null
                    }
                }
              if ($GetLogonUser -contains "AACDomain Users")
                {
                 net localgroup $LimtlocalUserGroup "AACDomain Users" /Delete | Out-Null
                }
            }
    [Carbon.Security.Privilege]::GrantPrivileges( $LimtlocalUserGroup , $Privilege )
    [Carbon.Security.Privilege]::RevokePrivileges( $DenylocalUserGroup , $Privilege ) 
    Return 10009
    

      

  • 相关阅读:
    c 语言练习__去掉多余的空白字符_修正
    c 语言练习__求到N的阶乘的和。
    <<c 和指针 >> 部分笔记。
    AsciiDoc Markup Syntax Summary
    gdb 基本命令
    Ubuntu开启防火墙
    转载 jre精简
    windows 下指定jre运行java程序批处理指令
    虚拟机vmware的NAT网络
    liunx 端口权限
  • 原文地址:https://www.cnblogs.com/vmsky/p/13698709.html
Copyright © 2011-2022 走看看