I'm creating a PSObject
in Powershell like this:
$NetworkInfo = New-Object PSObject
$NetworkInfo | Add-Member -type NoteProperty -Name IPAddress -Value "10.10.8.11"
$NetworkInfo | Add-Member -type NoteProperty -Name SubnetMask -Value "255.255.255.0"
$NetworkInfo | Add-Member -type NoteProperty -Name Gateway -Value "10.10.8.254"
$NetworkInfo | Add-Member -type NoteProperty -Name Network -Value "10.10.8.0"
$NetworkInfo | Add-Member -type NoteProperty -Name DNS1 -Value "10.10.10.200"
$NetworkInfo | Add-Member -type NoteProperty -Name DNS2 -Value "10.10.10.201"
$NetworkInfo
I want to do a specific action for each NoteProperty in this PSObject, but I'm not sure how to go about doing that. For example (even though I know it's the wrong way to do it) this code:
ForEach ($noteProperty in $NetworkInfo) {
Write-Host $noteProperty
}
Only outputs the entire object as an array:
@{IPAddress=10.10.8.11; SubnetMask=255.255.255.0; Gateway=10.10.8.254; Network=10.10.8.0; DNS1=10.10.10.200; DNS2=10.10.10.201}
EDIT: Each NoteProperty
is of the variable type System.String
- if that's pertinent.
Am I creating the object incorrectly, or do I just not understand how to go through the object?