Search string in a array - newbie


i trying output of wmiobject , analyse network adapter based on ip address assigned , if ip address matches criterai, need rename network connection managemt or production.

i able capture out put of get-wmiobject in variable.

$computer = "localhost"
$namespace = "root\cimv2"

$i=get-wmiobject -class win32_networkadapterconfiguration -computername $computer -namespace $namespace  | format-list ipaddress
$i

the output of code is

 

ipaddress :

ipaddress : {144.***.***.53}

ipaddress :

ipaddress : {192.168.***.***, fe8a::4ca3:bbdf:4a9d:c539}

ipaddress :

i need filter ip address satrts 144 "production " , 192 "management" based on need mac address of nic card.

i getting confused while searching string.

 

 

try this:

 

$mac = @{}
gwmi win32_networkadapter |% {$mac.add($_.deviceid,$_.macaddress)}
gwmi win32_networkadapterconfiguration |%{
 if ($_.ipaddress -like "144*"){write-host "production ip $($_.ipaddress) mac $($mac."$($_.index)")"}
 if ($_.ipaddress -like "192*"){write-host "management ip $($_.ipaddress) mac $($mac."$($_.index)")"}
 }

 

 


[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group