Powershell -Filter not accepting two conditions

后端 未结 3 1925
故里飘歌
故里飘歌 2021-01-28 21:01

I have this command

$remoteuserlist = Get-WmiObject Win32_UserAccount `
-filter \"LocalAccount =True\" –computername $PC -verbose

that I am run

相关标签:
3条回答
  • 2021-01-28 21:39
    $remoteuserlist = Get-WmiObject Win32_UserAccount -filter {LocalAccount = "True" and Name != "Guest"} –computername $PC -verbose
    
    1. You were mixing WMI syntax and PowerShell syntax
    2. The brackets encompassing the filter were around the other parameters of Get-WmiObject
    0 讨论(0)
  • 2021-01-28 21:50

    The WQL "not equal" operator is != or <>.

    WQL Operators

    0 讨论(0)
  • 2021-01-28 21:51

    If you have a bunch of old VBScript WMI queries laying around you can use the Get-WMIObject -Query param to reuse them.

    $remoteuserlist = Get-WmiObject -query "SELECT * FROM Win32_UserAccount WHERE LocalAccount = 'True' and Name != 'Guest'" –computername $PC -verbose
    

    Not groundbreaking but it can help if you don't want to rewrite queries.

    0 讨论(0)
提交回复
热议问题