locked
Hello, begginer here, i have a stupid question Get-ADComputer RRS feed

  • Question

  • Hi , sorry i searched a couple of hours , i am newbie  and i need help. 

    using 

    $computers = Get-Content .\group.txt  # (a list with computers name)
      foreach ($computer in $computers) {
    $Groups = Get-ADComputer  -Filter {Name -eq $computer} -SearchBase "DC=mydomain,DC=.com" -Server "mydomain.com" -Properties Enabled | FT Name,DNSHostName,Enabled }  

    Here the output is more that one table (header and content; header and content) 

    How can i group this ouput to one table? i want to see it on the screen after that i will manage to export to file.

    I tried  to add this  , but with no succes:  

    [pscustomobject]@{
           Name = $group.Name
        FQDN = $group.DNSHostName
       Enabled = $group.Enabled
        }

    Thank you



    • Edited by lentzy007 Wednesday, October 17, 2018 1:25 PM
    Wednesday, October 17, 2018 1:18 PM

Answers

  • Note that you can also just do this:

    Get-Content .\group.txt | Get-ADComputer  | Format-Table Name,DNSHostName,Enabled


    \_(ツ)_/

    • Proposed as answer by Richard MuellerMVP Wednesday, October 17, 2018 6:58 PM
    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:31 PM
    Wednesday, October 17, 2018 5:27 PM
  • Hello,

    you could accomplish this by using the following:

    $computers = Get-Content .\group.txt  # (a list with computers name)
    $Groups = @()
    foreach ($computer in $computers) {
    $Groups += Get-ADComputer  -Filter {Name -eq $computer} -SearchBase "DC=mydomain,DC=com" -Server "mydomain.com" -Properties Enabled | Select-Object -Property Name,DNSHostName,Enabled }

    # Display as table on screen
    $Groups | Format-Table
    • Proposed as answer by Martin Norlunn Wednesday, October 17, 2018 1:47 PM
    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:31 PM
    Wednesday, October 17, 2018 1:46 PM
  • Hi,

    Thanks for your question.

    I agree with Jrv. 

    Get-Content .\group.txt | Get-ADComputer  | Format-Table -property Name,DNSHostName,Enabled | out-file -path $filepath

    "Out-file" cmdlet can help you export to file.

    Best Regards,

    Lee


    Just do it.

    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:33 PM
    Thursday, October 18, 2018 5:41 AM
  • Get-Content .\group.txt |Get-ADComputer -Server domain.com | Format-Table Name,DNSHostName,Enable

    it works, simple and plain. Thank you

    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:32 PM
    Thursday, October 18, 2018 1:18 PM

All replies

  • Hello,

    you could accomplish this by using the following:

    $computers = Get-Content .\group.txt  # (a list with computers name)
    $Groups = @()
    foreach ($computer in $computers) {
    $Groups += Get-ADComputer  -Filter {Name -eq $computer} -SearchBase "DC=mydomain,DC=com" -Server "mydomain.com" -Properties Enabled | Select-Object -Property Name,DNSHostName,Enabled }

    # Display as table on screen
    $Groups | Format-Table
    • Proposed as answer by Martin Norlunn Wednesday, October 17, 2018 1:47 PM
    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:31 PM
    Wednesday, October 17, 2018 1:46 PM
  • You are both close but not quite there.

    Get-Content .\group.txt |
        ForEach-Object{
            Get-ADComputer  $_
        } | 
        Format-Table Name,DNSHostName,Enabled
    When searching for a computer name there is no need for "SearchBase","Server" as the name is unique with computers.  "Properties" is not required here as the properties being used are all default.


    \_(ツ)_/


    • Edited by jrv Wednesday, October 17, 2018 5:25 PM
    Wednesday, October 17, 2018 5:23 PM
  • Note that you can also just do this:

    Get-Content .\group.txt | Get-ADComputer  | Format-Table Name,DNSHostName,Enabled


    \_(ツ)_/

    • Proposed as answer by Richard MuellerMVP Wednesday, October 17, 2018 6:58 PM
    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:31 PM
    Wednesday, October 17, 2018 5:27 PM
  • Hi,

    Thanks for your question.

    I agree with Jrv. 

    Get-Content .\group.txt | Get-ADComputer  | Format-Table -property Name,DNSHostName,Enabled | out-file -path $filepath

    "Out-file" cmdlet can help you export to file.

    Best Regards,

    Lee


    Just do it.

    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:33 PM
    Thursday, October 18, 2018 5:41 AM
  • Hi,

    I use SeachBase, Server because i am searching in other domain (than the one where the server from where i am searching is joined )  . one with who i have trust (i hope i manage to explain corectly).

    Thursday, October 18, 2018 12:42 PM
  • Get-Content .\group.txt |Get-ADComputer -Server domain.com | Format-Table Name,DNSHostName,Enable

    it works, simple and plain. Thank you

    • Marked as answer by lentzy007 Thursday, October 18, 2018 1:32 PM
    Thursday, October 18, 2018 1:18 PM
  • Hi,

    Works. Thank you!

    Thursday, October 18, 2018 1:22 PM
  • Thank you!
    Thursday, October 18, 2018 1:23 PM