Get Active Directory Information from PC's in a text file - Powershell -


i running issue powershell command line i'm attempting run. needing pc name , lastlogondate pc's in list of text files powershell.

here code i'm attempting run:

get-content c:\hosts.txt | foreach-object{get-adcomputer $_ -properties name,lastlogondate | select-object name,lastlogondate | export-csv c:\output.csv} 

when run code error stating: "cannot find object identity: 'computername'" despite fact pc in ad. confusing me after foreach-object runs great if run itself. when add get-content , foreach-object errors begin. can see error messages each individual computer name being read text file, wonder if passing in way get-adcomputer doesn't like.

a couple things. first see what's in hosts.txt file. second thing move export-csv command outside of foreach-object statement. if leave how is, return last object processed in csv file. i've posted example of how should be.

get-content c:\hosts.txt | foreach-object {get-adcomputer $_ -properties name,lastlogondate | select-object name,lastlogondate} | export-csv c:\output.csv 

i'm not able replicate problem , thing different contents of hosts.txt file helpful see it.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -