Get-adcomputer

Welcome Forums General PowerShell Q&A Get-adcomputer

Viewing 15 reply threads
  • Author
    Posts
    • #247780
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Hi,

      I’m new to this forum and beginner to Powershell too and not sure if it’s right forum to get some help on my query.

      I believe i will not be a beginner like now if i keep reading and practicing from this space. 😉

      Not sure what’s wrong here but it returns nothing. 🙁

       

    • #247786
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Ranjithkumar

      You switched the quotation marks. Try this:

      [/crayon]

      You might consider another loop type …

      [/crayon]

      As the attribute “Name” already is part of the default subset Get-ADcomputer returns you don’t have to specify it explicitly for -Properties. 😉

    • #247795
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      It’s awesome. Thanks for pointing this out. It worked.

      And you was very fast too. 🙂

    • #247807
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Okay. Here I’ve come with another one very fast.

      While I’m entering many computer names i.e. 80 Computers, It returns error as

       

      Get-ADComputer : Cannot find an object with identity: ‘<Computername> ‘ under: ‘<DomainName>’.

      I have tried keying in -searchbase, -searchscope and -server too.

    • #247816
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Sorry. I think. I have got this. There were extra spaces on each computer names. That was the issue.

    • #247819
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Get-ADComputer : Cannot find an object with identity: ‘<Computername> ‘ under: ‘<DomainName>’.

      I’d suspect that you have computer names in your list that are not in your AD – maybe typos. Can you check this?

    • #247822
      Participant
      Topics: 12
      Replies: 38
      Points: 261
      Helping Hand
      Rank: Contributor

      Does it work if you run the Get-ADComputer command using one of the names from the list?
      Get-ADComputer -filter ‘Name -eq “ServerA”‘ -Properties *|select -Property Name,OperatingSystem -verbose

      What happens if you pick a name from the list by doing this:
      $computers[0]|ForEach-Object -Process {Get-ADComputer -filter &#039;Name -eq &quot;$_&quot;&#039; -Properties *|select -Property Name,OperatingSystem -verbose}

      Hah hah, I guess I should have refreshed after having the tab open for a bit…

    • #247834
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Here’s the next stop. To get the output as csv file. It generates header names for each computer result.
      i.e. like below.

      Name OperatingSystem
      —- —————
      Computername Windows 10 Enterprise

      Name OperatingSystem
      —- —————
      Computername Windows 10 Enterprise

      Name OperatingSystem
      —- —————
      ComputernameWindows 10 Enterprise

      Name OperatingSystem
      —- —————
      Computername Windows 7 Enterprise

      Name OperatingSystem
      —- —————
      Computername Windows 10 Enterprise

      Updated script

    • #247837
      Participant
      Topics: 0
      Replies: 78
      Points: 348
      Helping Hand
      Rank: Contributor

      Use Export-Csv -Path C:\test\Output\Result.csv -Notype rather than Out-File -FilePath C:\test\Output\Result.csv -Append.

      Export-Csv will set the first row as the header row. The remaining rows will be data. Export-Csv -Delimiter &#039;character&#039; allows for a different delimiter ( character) than the default comma.

    • #247843
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP
      [/crayon]

      You may make a step back and keep learning the basics of Powershell a little further. 😉

    • #247861
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Get-ADComputer : Cannot find an object with identity: ‘<Computername> ‘ under: ‘<DomainName>’.

      I’d suspect that you have computer names in your list that are not in your AD – maybe typos. Can you check this?

      Yes. You’re right. There were spaces at end of each computer names while i copied them from an excel.

    • #247864
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Does it work if you run the Get-ADComputer command using one of the names from the list?

      Get-ADComputer -filter ‘Name -eq “ServerA”‘ -Properties *|select -Property Name,OperatingSystem -verbose

      What happens if you pick a name from the list by doing this:

      $computers[0]|ForEach-Object -Process {Get-ADComputer -filter 'Name -eq "$_"' -Properties *|select -Property Name,OperatingSystem -verbose}

      Hah hah, I guess I should have refreshed after having the tab open for a bit…

      NP. Thanks for your helping mind. 🙂

    • #247867
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Use Export-Csv -Path C:\test\Output\Result.csv -Notype rather than Out-File -FilePath C:\test\Output\Result.csv -Append.

      Export-Csv will set the first row as the header row. The remaining rows will be data. Export-Csv -Delimiter 'character' allows for a different delimiter ( character) than the default comma.

      Thanks much. I’ll use the same as suggested.

    • #247873
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      $computerList = Get-Content "C:\test\Input\Computers.txt"<br />foreach ($ComputerName in $computerList) {<br />    Try {<br />        Get-ADComputer -Identity $ComputerName -Properties Operatingsystem -ErrorAction Stop |<br />        Select-Object -Property Name, OperatingSystem | Export-Csv -Path C:\test\Output\Result.csv -Append</p><p>    }<br />    catch {<br />        $ComputerName | Out-File -FilePath C:\test\Output\UnAvailable.txt -Append<br />    }<br />} You may make a step back and keep learning the basics of Powershell a little further. 😉

      Thanks @Olaf.

      Actually I keep on watching different lectures from Youtube(Don Jones) & LinkedLearning(Jason Helmick, Matt Hester, Adam Bertram). Due to lack of practice i end up in different or wrong commands rather than the appropriate one. But Thanks for you kind advise, I’ll continue to do that. 🙂

      If you could share any PowerShell learning path to move from beginner, that would be really great..!! Thanks in advance. 🙂 Have a good weekend.

       

    • #247876
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Actually I keep on watching different lectures from Youtube(Don Jones) & LinkedLearning(Jason Helmick, Matt Hester, Adam Bertram). Due to lack of practice i end up in different or wrong commands rather than the appropriate one. But Thanks for you kind advise, I’ll continue to do that. 🙂

      If you could share any PowerShell learning path to move from beginner, that would be really great..!! Thanks in advance. 🙂 Have a good weekend.

      I think you’re doing just fine. What I’d like to recommend though is to search for a solution first before you ask in forum like this. Most questions a beginner has have been aswered already in the past. 😉

      Yes. You’re right. There were spaces at end of each computer names while i copied them from an excel.

      If you have to use a source like this and you cannot count on the quality of the source data you could try to use the .trim() method to remove spaces (or other unwnated charachters) from strings you need to use. Example:

      [/crayon]
    • #247888
      Participant
      Topics: 1
      Replies: 9
      Points: 10
      Rank: Member

      Thanks @olaf

Viewing 15 reply threads
  • You must be logged in to reply to this topic.