Powershell - 获取Android设备的序列号

时间:2013-08-16 22:10:39

标签: android powershell

在这里输入代码我正在使用PowerShell将Android软件包部署到多个设备(我是PowerShell的新手)。我使用“adb devices”获取设备列表,其输出如下所示:

List of devices attached
ca677f63        device
emulator-5554   device
<blank line>

我只想获得设备的序列号。这是我的尝试。

1)为了跳过最后一个空白行,我得到了这样的行号:

$devices=adb devices
$lines=($devices | measure-object -Line).lines

2)我的最终命令是这样的:

$deviceList=$devices | select -skip 1 | select -first ($lines-1) | foreach-object { $_ -replace('device')}

我的问题:这是最好的方式还是有更清洁有效的方式?

1 个答案:

答案 0 :(得分:1)

您可以尝试:

$devices=adb devices
$devices | where {$_ -match '(.*)device$'} | % {$Matches[1]}

我选择正则表达式,对所需的字符进行分组,所有行以n#39; device&#39;结尾。

相关问题