Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

unable to extract ipv4 address only from a variable storing both ipv4 & ipv6

$
0
0

Hello

using Regex, i want to extract only the ipv4 address from a variable ($NICIpAdd) which contains both ipv4 & ipv6 addresses & then show that ipv4add on the console. but i encounter error:

$netconnectionID= (gwmi win32_networkadapter -filter"index = 14").netconnectionID

$NICipadd= (gwmi win32_networkadapterconfiguration -filter"index = 14").ipaddress

$NICipadd

PS C:\> $NICipadd

10.1.1.2

fe80::ddff:46f0:8804:859b

$NICipaddv4=Get-Content$NICipadd | where {$_-notmatch':'}

write-host"$netconnectionID $NICipaddv4"

# the error message is :

Get-Content : Cannot find path 'C:\10.1.1.2' because it does not exist.

At line:1 char:27

+     [string]$NICipaddv4 = Get-Content $NICipadd | where {$_ -notmatch ':'}

+                           ~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (C:\10.1.1.2:String) [Get-Content], ItemN 

   otFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentComm 

   and

 Get-Content : Cannot find a provider with the name 'fe80'.

At line:1 char:27

+     [string]$NICipaddv4 = Get-Content $NICipadd | where {$_ -notmatch ':'}

+                           ~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (fe80:String) [Get-Content], ProviderNotF 

   oundException

    + FullyQualifiedErrorId : ProviderNotFound,Microsoft.PowerShell.Commands.GetContent 

   Command

 

 


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images