Avatar of bibi92
bibi92Flag for France

asked on 

powershell format result of command

Hello

I search to format result on the below command :

$NetIPAddresses = (Get-NetIPAddress | where {$_.InterfaceAlias -match "10" -and $_.AddressFamily -eq "IPv4"}
) |  format-table IPAddress, InterfaceAlias -auto

echo $NetIPAddresses

IPAddress     InterfaceAlias
---------     --------------
112.164.60.9  HT-10
10.111.22.59  DT-10
10.111.22.58  DT-10
10.111.22.56  DT-10
10.111.160.90 AD-10

I want to group the result in three columns without column name:


10.111.22.59;10.111.22.58;10.111.22.56,112.164.60.9,10.111.160.90

Thank you

Best regards
Powershell

Avatar of undefined
Last Comment
oBdA
Avatar of oBdA
oBdA

This should do it; but note that now you don't really know anymore which entry belongs to which InterfaceAlias if you run this on a machine with a different configuration.
This sorts the output by the InterfaceAlias (so AD, DT, HT), so the output should actually be
10.111.160.90, 10.111.22.59;10.111.22.58;10.111.22.56, 112.164.60.9

Open in new window

Or do you need the actual order DT, AD, HT, and can you rely upon these always being there?
(
	Get-NetIPAddress |
		Where-Object {$_.InterfaceAlias -match "10" -and $_.AddressFamily -eq "IPv4"} |
		Group-Object -Property InterfaceAlias |
		Sort-Object Name |
		ForEach-Object {$_.Group.IPAddress -join ';'}
) -join ','

Open in new window

Avatar of bibi92
bibi92
Flag of France image

ASKER

I need the actual order DT, AD, HT

Thank you

Best regards
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo