Author Posts

September 18, 2015 at 3:02 am

hello, i'm totally new to Powershell. I'm trying to retrieve computer information, by using a text file with a list of computer names. but my line will not work. please help.

$CN = Get-Content -Path "c:\scripts\computername.txt" Get-EventLog -ComputerName $CN -LogName Application -Newest 10 | Export-Csv -Path "c:\scripts\test.txt".

The computers are in a Active Directory network. Should I be using Get-ADComputer?

September 18, 2015 at 3:39 am

Can you show what you have in computername.txt. Just the first few lines will be sufficient

September 18, 2015 at 3:56 am

What's not working?

It could just be the formatting of your post but if you're typing that all one line it won't work. You'll need a new line before continuing with Get-EventLog. This can be done in the ISE or type the lines, one at a time, in the console:

$CN = Get-Content -Path 'c:\scripts\computername.txt'
Get-EventLog -ComputerName $CN -LogName Application -Newest 10 | Export-Csv -Path 'c:\scripts\test.txt'

If it's not formatting and you're getting errors or a different problem, please provide more information.

Get-ADComputer is used for retrieving computer objects from Active Directory, it won't help you retrieve Event Log information from individual computers.

September 18, 2015 at 5:56 am

I have managed to fix it. i've used 2 lines as suggested by Matt and renamed the file to c.
how do change that to get win32_bions info instead?

September 18, 2015 at 6:02 am

I get an access denied when i run the following:

PS C:\Users\FM> $CN = Get-Content -Path 'c:\scripts\c.txt'
PS C:\Users\FM> Get-WmiObject -Class win32_bios -ComputerName $CN | Export-Csv -Path 'c:\scripts\test

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:1
+ Get-WmiObject -Class win32_bios -ComputerName $CN | Export-Csv -Path 'c:\scripts ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectC

Could it be that i don't have admin rights on the machine?

September 18, 2015 at 6:08 am

$CN = Get-Content -Path 'C:\test\NYTCNOU.txt'
Foreach ($computer in $cn){
    Get-EventLog -ComputerName $CN -LogName Application -Newest 10 | Export-Csv -Path 'c:\test\testNYOU.CSV'

It is recommended that you test the connection first, to make sure the PC is up and running.