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
Powershell 计算指定计算机对象的最大令牌大小?_Powershell_Active Directory_Tokenize - Fatal编程技术网

Powershell 计算指定计算机对象的最大令牌大小?

Powershell 计算指定计算机对象的最大令牌大小?,powershell,active-directory,tokenize,Powershell,Active Directory,Tokenize,我知道CheckMaxTokenSize.ps1(不幸的是TokenSZ.exe不再可用,只能在32位操作系统中工作),如何计算特定计算机对象的最大令牌大小?我能够修改一个脚本来查找递归成员对象的总数(每台计算机的最大MS数为1015),但需要进一步改进 下面是简单的powershell脚本 Import-Module ActiveDirectory $forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurr

我知道CheckMaxTokenSize.ps1(不幸的是TokenSZ.exe不再可用,只能在32位操作系统中工作),如何计算特定计算机对象的最大令牌大小?我能够修改一个脚本来查找递归成员对象的总数(每台计算机的最大MS数为1015),但需要进一步改进

下面是简单的powershell脚本

Import-Module ActiveDirectory
$forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath = [ADSI]"GC://$forestName"
$Search = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)
$computer = Read-Host "Computer Name"
Write-Host ""; Write-Host "Processing....." -nonewline
if ($computer -eq "") {$computer = "<BLANK>"}
$Search.Filter = "(&(objectCategory=Computer)(name=$computer))"
$computercn = $Search.FindAll().Properties.distinguishedname
$csv = dsget computer $computercn -memberof -expand
Write-Host ($csv.Length -1) "items in List" -ForegroundColor Green
Write-Host "-----------------------------------"
导入模块ActiveDirectory
$forestName=([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
$ADsPath=[ADSI]“GC://$forestName”
$Search=新对象系统.DirectoryServices.DirectorySearcher($ADsPath)
$computer=读取主机“计算机名”
写入主机“”;写入主机“处理…”-非脱机
如果($computer-eq“”){$computer=”“}
$Search.Filter=“(&(objectCategory=Computer)(name=$Computer))”
$computercn=$Search.FindAll().Properties.DiscrimitedName
$csv=dsget computer$computercn-memberof-expand
写入主机($csv.Length-1)“列表中的项目”-ForegroundColor绿色
写入主机“-------------------------------------”

如何在不在设备上的情况下返回AD计算机对象的令牌大小?

我建议您重新开始,并真正查看需要哪些信息,以便将此任务分解为简单的步骤

在开始之前,让我们回顾一下令牌大小公式:

# Calculate TokenSize based on groups
$TokenSize = 1200 + (40 * $LargeGroups.Count) + (8 * $SmallGroups.Count)

# Factory in SIDHistory principals
if($Computer.SIDHistory){
    $TokenSize += 40 * $Computer.SIDHistory.Count 
}
令牌大小=1200+40d+8s

此公式使用以下值:
d: 用户所属的域本地组数加上 用户帐户域之外的通用组数 用户是的成员加上安全性中表示的组数 ID(SID)历史记录。
s: 用户可以访问的安全全局组数 是的成员加上用户帐户中的通用组数 用户所属的域。
1200:的估计值 车票开销。此值可能会有所不同,具体取决于DNS等因素 域名长度、客户端名称和其他因素

假设您已经拥有计算机名(可能来自用户输入),我们需要的是:

  • 检索计算机帐户对象及其sid历史记录
  • 查找其所有组成员身份(递归)
  • 根据域和范围将组拆分为两个bucket
  • 那么,让我们开始工作吧。 由于您手边有
    ActiveDirectory
    模块,因此很容易找到计算机:

    # Define computer name
    $ComputerName = "computer01"
    
    # Find the computer in the directory
    $Computer = Get-ADComputer -LDAPFilter "(&(name=$ComputerName))" -Properties PrimaryGroup,SidHistory
    
    现在,我们可以使用
    Get-ADPrincipalGroupMembership
    cmdlet检索所有组成员身份,但它不支持递归搜索,因此我将在LDAP筛选器中使用带有
    Get-ADGroup
    的查询规则控件:

    # Locate a Global Catalog server
    $GC = Get-ADDomainController -Discover -Service GlobalCatalog
    
    # Search the global catalog using our recursive ldap filter
    $Groups = Get-ADGroup -LDAPFilter "(&(member:1.2.840.113556.1.4.1941:=$($Computer.DistinguishedName)))" -Server "$($GC.HostName):3268"
    
    # Don't forget the primary group
    $Groups = @($Groups; Get-ADGroup -Identity $Computer.PrimaryGroup)
    
    现在我们只需要将组分为两组,一组包含域本地组和外部通用组,另一组包含全局组和本地通用组:

    # These are the "d" groups from the original formula
    $LargeGroups = @($Groups |Where-Object {$_.GroupScope -eq 'DomainLocal' -or ($_.GroupScope -eq 'Universal' -and $_.DistinguishedName -notlike "*,DC=$($GC.Domain -split '\.' -join ',DC=')")})
    
    # These are the "s" groups from the original formula
    $SmallGroups = @($Groups |Where-Object {$_.GroupScope -eq 'Global' -or ($_.GroupScope -eq 'Universal' -and $_.DistinguishedName -like "*,DC=$($GC.Domain -split '\.' -join ',DC=')")})
    
    现在只需按照公式计算:

    # Calculate TokenSize based on groups
    $TokenSize = 1200 + (40 * $LargeGroups.Count) + (8 * $SmallGroups.Count)
    
    # Factory in SIDHistory principals
    if($Computer.SIDHistory){
        $TokenSize += 40 * $Computer.SIDHistory.Count 
    }
    

    我们完成了:-)

    ActiveDirectory模块,一个
    DirectorySearcher
    实例和
    dsget
    -你真的不能决定使用哪个工具集,是吗?无论如何,这里的实际问题是什么?您不确定计算最大令牌大小的公式吗?我知道这个公式,但不知道如何实现它。我不是编剧,只是想捏造一个解决方案。我为我的草率道歉。实际的问题是“如何让这个凌乱的脚本计算最大令牌大小,以便确保它在65535以下”$largegroups和$smallgroups为空:(脚本抱怨get-adgroup搜索筛选器无法识别,标识有空参数,$Computer是否包含任何内容?否。组,gc是否包含任何内容(顺便说一句,谢谢你)那么你知道问题是什么了☺ 确保$ComputerName包含正确的/现有的计算机名,尽管如此:)我无法获取$computer=get-ADComputer-LDAPFilter“(&(name=$ComputerName))”-属性PrimaryGroup,SidHistory以正常工作,即使ComputerName具有有效的计算机