Author Posts

March 8, 2018 at 9:50 am


I've started writing a script to migrate DHCP scopes from one server to another. I've like the scopes to be automatically taken from the source server, so I don't have to manually check and list them.

If I use something like the below command to get the scopes which it gives as an array (also listed below)

Is it possible to sort or filter the name(ScopeId) column to give me a result like,,

that I can use as a variable?

I've tried a few options but I've had no luck.

Get-DhcpServerv4Scope -ComputerName DhcpServerName | Group-Object ScopeId

Count Name Group
—– —- —–
1 {DhcpServerv4Scope}
1 {DhcpServerv4Scope}
1 {DhcpServerv4Scope}
1 {DhcpServerv4Scope}
1 {DhcpServerv4Scope}
1 {DhcpServerv4Scope}
1 {DhcpServerv4Scope}

March 8, 2018 at 10:45 am

Have you tried piping it to sort?


Get-DhcpServerv4Scope -ComputerName DhcpServerName | Group-Object ScopeId | Sort Name

March 8, 2018 at 2:43 pm

$a = (Get-DhcpServerv4Scope -ComputerName DhcpServerName | Group-Object ScopeId | 
  select -expand name) -join ','

March 8, 2018 at 2:51 pm

Thanks js just what I was looking for

$ScopeIds = (Get-DhcpServerv4Scope -ComputerName DHCPServerName).ScopeId -join ","