powershell - 使用-notlike在PowerShell中过滤出多个字符串

标签 powershell

我正在尝试为除两个以外的所有用户读取事件日志以进行安全审核,但是可以使用-notlike运算符来做到这一点吗?

就像这样:

Get-EventLog -LogName Security | where {$_.UserName -notlike @("*user1","*user2")}

我有它为单个用户工作,例如:
Get-EventLog -LogName Security | where {$_.UserName -notlike "*user1"}

最佳答案

V2至少包含-username参数,该参数采用string [],并支持通配。

您想像这样扩展V1的测试:

Get-EventLog Security | ?{$_.UserName -notlike "user1" -and $_.UserName -notlike "*user2"}

或者,您可以在内联数组上使用“-notcontains”,但这仅在您可以对用户名进行精确匹配时才有效。
... | ?{@("user1","user2") -notcontains $_.username}

关于powershell - 使用-notlike在PowerShell中过滤出多个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/848859/

相关文章:

powershell - Json 到 CSV 选择二级列

powershell - C# : Automated removal of unnecessary assembly references?

powershell - 为用户返回管理员 saccountname

powershell - 仅在嵌套循环中跳出内循环

string - 在 Powershell 中将长字符串分成几行

powershell - aws-cli (powershell) import-image 缺少必需参数 disk-images

sql-server - Powershell脚本在Windows 2008 R2上运行良好,但在Windows 2012 R2上不执行任何操作

powershell - WebView - 获取 Just ' Share Name'

powershell - -eq 是否适用于 Powershell 中的多个扩展

git - 警告和错误的记录不会写入 Powershell 中的日志文件