I am very new to powershell and am trying to extract a number from a variable. For instance, I get the list of ports using this command: $ports = [system.io.ports.serialport]::getportnames()
The contents of $ports is: COM1, COM2, COM10, COM16 and so on.
I want to extract the numbers from $ports. I looked at this question. It does what I want, but reads from a file.
Please let me know how to resolve this.
Thanks.
Edit: I was able to do what I wanted as follows:
$port=COM20
$port=$port.replace("COM","")
But if there is any other way to do this, I will be happy to learn it.