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