01 / ADDRESSING AND INVENTORY · LESSON 01

Build a network device inventory

Select the managed network devices and turn CSV management ports into numeric values.

12 min · learn at your pace

Define the population before the report

This export contains routers, switches, a firewall, a retired switch, and an application server. The fictional network team's scope is active Router, Switch, and Firewall rows. A device having an address does not automatically place it in that scope.

Filter on both State and Role. Preserve DeviceId as the stable identity: names and management addresses can change. Later lessons join observations by device and interface rather than assuming a port name is globally unique.

Keep data useful to the next command

Import-Csv returns strings. Convert ManagementPort to [int] so numeric comparisons and sorting behave numerically. The supplied ports have already been validated as integers in 1–65535. A collector accepting arbitrary input would need validation before conversion.

[int]'443' -gt [int]'22'

Emit objects, using ForEach-Object with [pscustomobject] or calculated Select-Object properties. Keep Format-Table for display at the end of a workflow; its formatting records are not an inventory another function can consume.

All addresses and devices are fictional. Reading this CSV does not discover devices or connect to a management service. The lab teaches the transformation that can sit behind a separately authorised collector.

Go deeper

Read the official reference.

Try an example.ps1
Import-Csv '/home/user/devices.csv' | Select-Object DeviceId, Name, Role, State
YOUR TURN

Put it into practice.

Read devices.csv and emit DeviceId, Name, Role, ManagementAddress, and numeric ManagementPort for active Router, Switch, and Firewall rows only. Preserve the source values and omit retired devices and servers. Order does not matter.

See an explained solution
One way to solve it.ps1
Import-Csv '/home/user/devices.csv' | Where-Object { $_.State -eq 'Active' -and $_.Role -in @('Router','Switch','Firewall') } | ForEach-Object { [pscustomobject]@{ DeviceId=$_.DeviceId; Name=$_.Name; Role=$_.Role; ManagementAddress=$_.ManagementAddress; ManagementPort=[int]$_.ManagementPort } }

The filter keeps three active network devices. Explicit numeric conversion makes the management-port property reusable without changing the device identity.