Hopefully easy > Computer Name from User Name (distinguishedName)

Welcome Forums General PowerShell Q&A Hopefully easy > Computer Name from User Name (distinguishedName)

Viewing 4 reply threads
  • Author
    Posts
    • #247080
      Participant
      Topics: 1
      Replies: 1
      Points: -6
      Rank: Member

      Want to get the Computer name of the User (User account I know).

      Hoping this makes sense below:

      #How can I ‘define’ this as what the error is?

       

      Thanks in advance for this one – will save me plenty of time.

      • This topic was modified 1 month, 3 weeks ago by kvprasoon. Reason: code formatting
      • This topic was modified 1 month, 3 weeks ago by kvprasoon. Reason: code formatting
    • #247122
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Simon, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “CODE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      # 3. need to drop ‘DistinguishedName” from 2. into the 3. [ManagedBy -eq {ManagedBy -eq ‘xx….xxx’ variable.

      So you have to save the result of Get-ADUser in a variable and use it for the filter for Get-ADComputer.

      #How can I ‘define’ this as what the error is?.

      What do you mean with that? What Error?

    • #247255
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      The following should work:

    • #247345
      Participant
      Topics: 1
      Replies: 1
      Points: -6
      Rank: Member

      @AdminOfThings45  && Thanks for the feedback and working answer.

      Most important thanks for the explanation and notes – learning for the day.

      The script above does exactly as requested.  Initially a few time outs however still produced result.

       

      For anyone else I added a new first line to the above to assist in my environment:

      Import-Module ActiveDirectory

       

      Top of the day to you.

       

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

      For anyone else I added a new first line to the above to assist in my environment:

      Import-Module ActiveDirectory

      Since Powershell version 3 that’s unnecessary. A properly installed module will be imported automatically by Powershell if needed.

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