getting computer information

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Wilfredo Perez Wilfredo Perez 1 year, 10 months ago.

  • Author
  • #29896
    Profile photo of Francisco Machado
    Francisco Machado

    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?

  • #29899
    Profile photo of Richard Siddaway
    Richard Siddaway

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

  • #29908
    Profile photo of Matt Bloomfield
    Matt Bloomfield

    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.

  • #29910
    Profile photo of Francisco Machado
    Francisco Machado

    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?

  • #29911
    Profile photo of Francisco Machado
    Francisco Machado

    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?

  • #29912
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    $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.

You must be logged in to reply to this topic.