Following this post, I can use cmd
's mode
command to see the available / free ports. I can also use the PowerShell (PS) 's oneliner:
Get-WMIObject Win32_SerialPort | Select-Object DeviceID
to see all the existing ports. The difference indicates the Open / busy ports.
Now I want to interrupt (force close) the ports which are open in any way, including the ones opened outside cmd
/PS. Please consider
- The port is not necessarily opened inside PS. otherwise I could use
$<PortName>.Close()
to do this. - It has to be a
cmd
or PS command, not a GUI solution, such as editing the registry or restating the operating system. - I don't want to delete / destroy the port. I just want to be sure they are free (ready to be opened)
- It should be preferably a one-liner. Something I can run in just one line. Using piping is ok.
P.S. I have also posted the question here on Reddit