我看到有人发布了这个小脚本分配Gid的,但不幸的是,我得到一个错误。 我修改了一下,以更好地适应我的需求,但不知道什么$组variables的意思呢? (见下文)
每当我尝试运行它时,都会收到错误消息
###Find the highest GID used on any group in the domain $highGid = Get-ADGroup -Searchbase $searchbase -LDAPFilter "(gidNumber=*)" -Properties gidNumber | Measure-Object -Property gidNumber -Maximum | Select-Object -ExpandProperty Maximum ###Avoid assigning GIDs below 1000000 $highGid = [Math]::max( $highGid, 1000000 ) ####Find every security group without a gidNumber, and give it one. $groups = Get-ADGroup -SearchBase $searchbase -LDAPFilter "(!gidNumber=*)" | ? {$_.GroupCategory -eq "Security"} $groups | Set-ADGroup -Add @{ gidNumber=++$highGid }
$groups使用看起来像是将2行代码合并为一个失败的尝试。
这可能是代码最初的样子:
$groups = Get-ADGroup -LDAPFilter "(!gidNumber=*)" | ? {$_.GroupCategory -eq "Security"} $groups | Set-ADGroup -Add @{ gidNumber=++$highGid }
这是一个单线的等价物:
Get-ADGroup -LDAPFilter "(!gidNumber=*)" | ? {$_.GroupCategory -eq "Security"} | Set-ADGroup -Add @{ gidNumber=++$highGid }
$gighGid必须定义为System.Double 。 我没有任何GID被分配到我的域中的AD对象,所以我不能testing这个,但是你可能只需要把$ highGid投到一个int地方。 在第一行这样做最有意义,就像这样:
$highGid = [int](Get-ADGroup ...)