0

I see someone posted this small script for assigning Gid's but unfortunately im getting an error. I modified it a bit to better fit my needs but was wonder what the $groups variable meant in it? (See below)

I get an error whenever i try to run it

###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 }
1
  • Please fix the formatting so the script becomes readable, and include the error message you are receiving. Aug 20, 2015 at 16:43

1 Answer 1

3

That use of $groups looks like a failed attempt at combining 2 lines of code in to one.

This is probably what the code originally looked like:

$groups = Get-ADGroup -LDAPFilter "(!gidNumber=*)" | ? {$_.GroupCategory -eq "Security"}
$groups | Set-ADGroup -Add @{ gidNumber=++$highGid }

And this is the equivalent as a one-liner:

Get-ADGroup -LDAPFilter "(!gidNumber=*)" | ? {$_.GroupCategory -eq "Security"} | Set-ADGroup -Add @{ gidNumber=++$highGid }

$gighGid must be defined as System.Double. I don't have any GID's assigned to AD object in my domain, so I can't test this, but you could probably just cast $highGid to an int somewhere. It would make the most sense to do it on the first line, like so:

$highGid = [int](Get-ADGroup ...)
4
  • So I tried that as well, unfortunately any way i slice it, i get the following error: Set-ADGroup : Invalid type 'System.Double'. Parameter name: gidNumber At line:13 char:11 + $groups | Set-ADGroup -Add @{ gidNumber=++$highGid } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (CN=Test_group_r...DC=com:A DGroup) [Set-ADGroup], ArgumentException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Micros oft.ActiveDirectory.Management.Commands.SetADGroup
    – robc60
    Aug 20, 2015 at 18:27
  • Please edit your original question to include the actual code you are using.
    – longneck
    Aug 20, 2015 at 19:07
  • I've gone ahead and edited the original code to include original
    – robc60
    Aug 20, 2015 at 19:33
  • see my edit. in the future, please provide the actual code you are using, in the exact format you are using it, and the error message. if you had done that to begin with, i could have given you all of this the first time without the back-and-forth.
    – longneck
    Aug 20, 2015 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .