Как это получается, я не так хорош в этом, но, может быть:
$comPortNumber = Get-WMIObject win32_potsmodem | where-object {$_.DeviceID -like "*05C6*"} | foreach {$_.AttachedTo}
# 05C6 is the Vendor ID for Qualcomm, AttachedTo returns the Com port number
if (!$comPortNumber) { Return "No Gobi Card Detected!" }
else {
$port = New-Object System.IO.Ports.SerialPort
$port.PortName = $comPortNumber
$port.BaudRate = "9600"
$port.Parity = "None"
$port.DataBits = 8
$port.StopBits = 1
$port.ReadTimeout = 9000 # 9 seconds
$port.DtrEnable = "true"
$port.open() #opens serial connection
Start-Sleep 2 # wait 2 seconds until device is ready
$port.Write("AT$")
$port.Write("QCGSN `r") #writes your content to the serial connection
try
{
while($myinput = $port.ReadLine())
{
$myinput
}
}
catch [TimeoutException]
{
# Put handling code here
}
finally
{
# Put the clean up code here
}
$port.Close() #closes serial connection
}