locked
Problems selecting numbers from string RRS feed

  • Question

  • Hi All,

    I have a large array of string values, each of which are reasonably the same but I need to retrieve three digits which make up the VLAN id from a network adapter object

    An example string is as follows:

    Domain|TestDevGroup|IP-10.20.30.0-VL222-Ref

    I have managed to create the following Regular expression: VL(.+)[0-9]{2,3}

    This gives me the result 'VL222' which is near to what I want but does anyone know how I can select only the digits without the leading VL?

    Also, I cant find out how I apply this query against an array string in PowerShell

    for example if the network names were a single column in a .csv file:

    $nics = import-csv nics.csv

    foreach($nic in $Nics){

    $Vlan = $nic | select-string -pattern 'VL(.+)[0-9]{2,3}'

    }

    Does not seem to work

    Hopefully one of you can shed some light on a newb like me?

    Thanks,

    Tuesday, October 20, 2020 3:16 PM

All replies