0

I've tried to find a solution by myself and I apologize if it was already answered somewhere but I could'nt make this work by myself.

I have written a script that list of wifi networks, get different informations and put them in a hash table. From there I've created a PSObject.

The code looks like this :

$WLANS=@{}
$wlanData = netsh wlan show networks mode=BSSID

( ... Here i extract all the info from $Wlandata ...)

    $WLANS.SSID = $SSID
    $WLANS.BSSID = $BSSID
    $WLANS.RSSI = $RSSI

$(foreach ($ht in $WLANS){new-object PSObject -Property $ht}) | Format-Table -AutoSize

The outpout looks like this :

RSSI       SSID               BSSID
----       ----               -----
{97, 16}   {TEST, SFR-6019}    {xx:xx:xx:xx:xx:xx, yy:yy:yy:yy:yy:yy}

and i want it to look like this :

RSSI       SSID               BSSID
----       ----               -----
97         TEST               xx:xx:xx:xx:xx:xx
16         SFR-6019           yy:yy:yy:yy:yy:yy

I have tried different things but i always get the same kind of output. If anybody can help it would be greatly appreciated !

2 Answers 2

1

Instead of putting the properties in a hashtable you need to build a custom object. It would look like this

$Processes = Get-Process | select -first 2
$CustomObj = Foreach ($Process in $Processes)
{
    [pscustomobject] @{
    'Name' = $Process.ProcessName
    'Handles' = $Process.Handles
    'Comment' = 'test123'
    }
}
$CustomObj

So you have your array, you iterate through the array and each loop builds a single custom object with your name/value pairs. The individual objects are then collected in the object array $CustomObj

Sign up to request clarification or add additional context in comments.

1 Comment

I have re-written my script to create an object and it worked ! Thanks :)
1

Hmm i see to less code. I think you missed a loop. Try this foreach wlan you select data:

$WLANS=@{}

$CurrentWLAN = "" | Select-Object -Property SSID, BSSID, RSSI

$CurrentWLAN.SSID = $SSID
$CurrentWLAN.BSSID = $BSSID
$CurrentWLAN.RSSI = $RSSI

$WLANS += $CurrentWLAN

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.