locked
Get-ADComputer foreach loop error RRS feed

  • Question

  • COuld any one help on below script I get error : 

    Script : 

     

    $comps = Get-Content -Path C:\Users\adey\Desktop\computers.txt

    foreach ($comp in $comps)

    {  

    $compdata = get-adcomputer $comp -properties PasswordLastSet |ft Name,PasswordLastSet

       write-host "$comp" 
       Write-Host "$compdata"

       }

    -----------------------------------------------------------------------------------------------------------------------------------

    Out Put : 

    PS H:\> S:\Ares\GetLastPwdChange.ps1

    -----------------------------------------------------------------------------------------------------------------------------------

    I'm new to PS. Could any one please suggest correction on this script

    Wednesday, June 10, 2020 6:08 AM

Answers

  • This would be how to use PowerShell to output those names.

    Get-Content C:\Users\adey\Desktop\computers.txt |
        Get-AdComputer -properties PasswordLastSet |
        Format-Table Name,PasswordLastSet
    


    \_(ツ)_/

    • Marked as answer by AresDem Sunday, June 14, 2020 11:23 AM
    Wednesday, June 10, 2020 7:37 AM

All replies

  • You forgot to post the output.  You also have failed to say what you are trying to do.

    Start by reading eh following:

    I also suggest starting with this book on PowerShell as it will teach you enough to understand how to ask a question and to explain what you are tryin to do.


    \_(ツ)_/

    Wednesday, June 10, 2020 7:33 AM
  • This would be how to use PowerShell to output those names.

    Get-Content C:\Users\adey\Desktop\computers.txt |
        Get-AdComputer -properties PasswordLastSet |
        Format-Table Name,PasswordLastSet
    


    \_(ツ)_/

    • Marked as answer by AresDem Sunday, June 14, 2020 11:23 AM
    Wednesday, June 10, 2020 7:37 AM
  • Thanks a lot for guiding. Yes I'm absolutely new to PS & firsttimer here. I absolutely forgot to define the purpose of the script. Will add more details next times. And thanks a ton for that ebook link, its really helpful . 
    Sunday, June 14, 2020 11:23 AM
  • I was exactly looking for this output but unnecessarily complicated the script. . Thanks a lot. 
    Sunday, June 14, 2020 11:24 AM