locked
filtering hostname from the output RRS feed

  • Question

  • Hi All,

    Below command will give us the list of machines which are associated with account "john.hilton" from the domain "ags.com". This command is working pretty fine and giving us the list of host names. 

    Now i want to check whether the host where i am running this script is also in the list or not. If the host name is in the list it should return hostname. if host name is not in the list then it should not return anything. How can i achieve this?

    below is the command i am running.

    ((Get-ADUser -Server ags.com -Identity "john.hilton" -Properties LogonWorkstations).LogonWorkstations).split(",") | findstr hostname
    Thursday, June 20, 2019 3:33 PM

Answers

  • We can also simplify it like this:

    if((Get-ADUser jsmith -Properties LogonWorkstations).LogonWorkstations -match $env:COMPUTERNAME){$env:COMPUTERNAME}


    \_(ツ)_/

    • Marked as answer by prabasb Friday, June 21, 2019 7:12 AM
    Thursday, June 20, 2019 4:27 PM

All replies

  • Not a good way to start so try this:

    $ws = (Get-ADUser -Server ags.com -Identity "john.hilton" -Properties LogonWorkstations).LogonWorkstations -split ','
    $ws if($ws -contains $env:COMPUTERNAME){$env:COMPUTERNAME}


    \_(ツ)_/

    Thursday, June 20, 2019 4:24 PM
  • We can also simplify it like this:

    if((Get-ADUser jsmith -Properties LogonWorkstations).LogonWorkstations -match $env:COMPUTERNAME){$env:COMPUTERNAME}


    \_(ツ)_/

    • Marked as answer by prabasb Friday, June 21, 2019 7:12 AM
    Thursday, June 20, 2019 4:27 PM