PowerShell查找数组内容、搜索数组、查询数组的方法

lijindongjindong 26 0 PDF 2021-02-01 16:02:32

PowerShell中有-contain、-like、-in等操作符,使用这些操作符,可以很方便的在数组中查找元素内容。其中in操作符貌似要在PowerShell 3.0中才有。 先看一个例子,将Windows目录的所有文件的文件名放入到数组$name中,然后在数组$name中查找exploer.exe元素。且看-contains的魅力! 代码如下: PS> $names = Get-ChildItem -Path $env:windir | Select-Object -ExpandProperty Name PS> $names -contains ‘explorer.exe’ True

用户评论
请输入评论内容
评分:
暂无评论