Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell-如何从变量中筛选值?_Powershell - Fatal编程技术网

Powershell-如何从变量中筛选值?

Powershell-如何从变量中筛选值?,powershell,Powershell,我设法从Invoke Webrequest获取变量的输出,如下所示。现在我只想过滤掉值6895,如何使用sourceIndex实现过滤器 sourceIndex innerText 我承认我不知道你所说的是什么意思,我如何使用sourceIndex实现过滤器?。[脸红] 但是,使用.Where()收集方法很容易找到包含目标值的对象。[咧嘴笑] 它的作用 创建要使用的数据集 使用Import CSV调用您的数据集,或者从I-WR调用中获取数据集,来替换所有这些 设置目标文本 使用.Where(

我设法从Invoke Webrequest获取变量的输出,如下所示。现在我只想过滤掉值6895,如何使用sourceIndex实现过滤器

sourceIndex innerText



我承认我不知道你所说的
是什么意思,我如何使用sourceIndex实现过滤器?
。[脸红]

但是,使用
.Where()
收集方法很容易找到包含目标值的对象。[咧嘴笑]

它的作用

  • 创建要使用的数据集
    使用
    Import CSV
    调用您的数据集,或者从
    I-WR
    调用中获取数据集,来替换所有这些
  • 设置目标文本
  • 使用
    .Where()
    收集方法筛选收集
  • 将上述内容分配给
    $Result
    变量
  • 在屏幕上显示
代码

#region >>> fake reading in a CSV file
#    in real life, repalce this entire block with a call to Import-CSV or the info from elsewhere
$IWR_Result = @'
sourceIndex, innerText
131, 8962
134, 6847
137, 6895
237, 3831
240, 1807
243, 1141
347, 7368
354, 4822
357, 9037
574, 383 831
583, 621 807
592, 281 141
'@ | ConvertFrom-Csv
#endregion >>> fake reading in a CSV file

$TargetInnerText = '6895'

$Result = $IWR_Result.Where({$_.InnerText -eq $TargetInnerText})

$Result
输出

sourceIndex innerText
----------- ---------
137         6895
sourceIndex innerText
----------- ---------
137         6895