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:
$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