gpt4 book ai didi

powershell - 选择要在ForEach-Object中使用的字符串

转载 作者:行者123 更新时间:2023-12-03 01:07:44 25 4
gpt4 key购买 nike

到目前为止,我有这个:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com