Author Posts

April 10, 2014 at 1:23 pm

Hello all,
I need some help
What I'm doing is basicly
1.scaning DHCP servers
2. Geting every details of every single scope from every single DHCP server in AD. ( a lot of scopes and a lot of servers 🙂 )
3 I need to have in one line "subnet , name of scope , on what server is that scope, status of that scope (active or disabled)"

First part – scanning DHCP servers from AD is done.
I got input file csv

dhcp_server,,first floor,,,259200,,Active,1396999818
backup,,first floor,,,259200,,Active,1396999831
backup2,,first floor,,,259200,,Disabled,1396999831
dhcp_server,,second floor,,,259200,,Active,1396999824

Output file should look like
Subnet,Scope Name,DHCP_server_#1,Status_#1,DHCP_server_#2,Status_#1,DHCP_server_#3,Status_#3,DHCP_server_#4,Status_#4,DHCP_server_#5,Status_#5,first floor,dhcp_server,Active,backup,Active,backup2,Disabled,,,,,second floor,dhcp_server,Active,,,,,,,,

Now I need to proccess input file.
I got

$DB = Import-Csv C:\Test\Subnets\DHCPCache_main.csv
$DB =$DB | Sort-Object subnet
$DB |select subnet, name,server , status | export-csv C:\Test\Subnets\temp.csv

I dont know how to deal with objects 🙁
For unique subnet (eg. $DB |Select-Object -Property subnet |Foreach {"$($_.subnet)"}) needs to be selected server , name, status

I undestand that it can be done like
foreach ($subnet in $subnets_unique){ $DB | where-object {$_.subnet -like $subnet }|select server , status }
but it showing me

subnet name server status
—— —- —— —— first floor dhcp_server Active first floor backup Active first floor backup2 Disabled second floor dhcp_server Active

Im looking for other output ;/. Dont know how to deal with objects and make object stucture

Subnet Name DHCP_server_#1 Status_#1 DHCP_server_#2 Status_#1 DHCP_server_#3 Status_#3 ......
—— —- ————– ——– ————– ——– ————– ———

Please help 🙂


April 10, 2014 at 3:06 pm

Look at the New-Object cmdlet and the Add-Member cmdlet. In terms of examples, go to Click through to the Toolmaking book and download the examples. They're free, and they show plenty of examples of constructing objects.