02 / INTERFACES AND CONFIGURATION · LESSON 05

Distinguish disabled, down, and unknown

Interpret administrative and operational state without treating absent evidence as an outage.

12 min · learn at your pace

Two state fields answer different questions

AdminState describes the configured intent in this export. OperState describes the observation. A port deliberately disabled by an administrator should not be counted in the same category as an enabled port observed down.

The lesson contract gives administrative Down precedence: classify it Disabled even if the operational field still says Up. For administratively Up ports, preserve observed Up or Down; otherwise use Unknown. This is an interpretation of a supplied snapshot, not a universal model of every vendor's interface states.

Import-Csv '/home/user/interfaces.csv' | Group-Object AdminState, OperState

Preserve the identity and uncertainty

Port names repeat on different devices. Always carry DeviceId and Port together into the result. Do not group every ge-1 into a single interface, and do not remove Unknown rows to make a report appear complete.

Unknown means the export did not establish the operational state. It is not equivalent to Down and should lead to a collection follow-up. Likewise, an Up observation does not prove end-to-end connectivity or application health.

Emit one object per input row. The following lessons use the same explicit identity and evidence rules when checking configuration and link observations.

Try an example.ps1
Import-Csv '/home/user/interfaces.csv' | Select-Object DeviceId,Port,AdminState,OperState
YOUR TURN

Put it into practice.

For every interfaces.csv row emit DeviceId, Port, and State. Administrative Down always means Disabled. Otherwise operational Up means Up, Down means Down, and Unknown means Unknown. Preserve all five interfaces; do not claim an unknown interface is down.

See an explained solution
One way to solve it.ps1
foreach ($port in Import-Csv '/home/user/interfaces.csv') {
    $state = if ($port.AdminState -eq 'Down') { 'Disabled' }
        elseif ($port.OperState -eq 'Up') { 'Up' }
        elseif ($port.OperState -eq 'Down') { 'Down' }
        else { 'Unknown' }
    [pscustomobject]@{ DeviceId=$port.DeviceId; Port=$port.Port; State=$state }
}

Administrative intent has precedence. A distinct Unknown result keeps the unavailable observation visible without turning it into a confirmed failure.