dealing with objects

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 3 years, 5 months ago.

  • Author
    Posts
  • #14462

    Szymon K
    Participant

    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

    server,subnet,name,min,max,lease_time,exlusion,status,timestamp
    dhcp_server,10.177.70.0/24,first floor,10.177.70.200,10.177.70.250,259200,,Active,1396999818
    backup,10.177.70.0/24,first floor,10.177.90.100,10.177.90.200,259200,,Active,1396999831
    backup2,10.177.70.0/24,first floor,10.177.90.100,10.177.90.200,259200,,Disabled,1396999831
    dhcp_server,10.177.71.0/24,second floor,10.177.71.100,10.177.71.250,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
    10.177.70.0/24,first floor,dhcp_server,Active,backup,Active,backup2,Disabled,,,,
    10.177.71.0/24,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
    —— —- —— ——
    10.177.70.0/24 first floor dhcp_server Active
    10.177.70.0/24 first floor backup Active
    10.177.70.0/24 first floor backup2 Disabled
    10.177.71.0/24 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 🙂

    Simon

  • #14464

    Don Jones
    Keymaster

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

You must be logged in to reply to this topic.