选择要在ForEach-Object中使用的字符串 [英] Selecting Strings to be used in ForEach-Object

查看:136
本文介绍了选择要在ForEach-Object中使用的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我有这个:

So far I have this:

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个,可以有更多或更少的内容.

I want to be able to select the string after All User Profile : and put it into an array, but it is only selecting a single letter. How do I select the strings instead? I want each array to be a different string, and there doesn't have to be 8 there can be more or less.

推荐答案

使用$ matches变量是正确的.

You are right to use the $matches variable.

$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
}

这篇关于选择要在ForEach-Object中使用的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆