我正在尝试为除两个以外的所有用户读取事件日志以进行安全审核,但是可以使用-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/