到目前为止,我有这个:
netsh wlan show profiles | Select-String '^ All User Profile : (.*)' | ForEach-Object {
$array +=
$_.Matches[0].Groups[1].Value
}
$array[0]
$array[1]
$array[2]
$array[3]
$array[4]
$array[5]
$array[6]
$array[7]
$array[8]
pause
我希望能够在
All User Profile :
之后选择字符串并将其放入数组中,但是它仅选择一个字母。我该如何选择字符串呢?我希望每个数组都是一个不同的字符串,并且不必一定是8,也可以有更多或更少的数组。
最佳答案
您正确使用$ matches变量。
$array = netsh wlan show profiles |
ForEach-Object {
if ($_ -match "\s*All User Profile\s*:\s*(.*)") { $($matches[1]) }
}
$array
foreach ($wn in $array) {
netsh wlan show profile name=$wn
}
关于powershell - 选择要在ForEach-Object中使用的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45244903/