getting computer information

Welcome Forums General PowerShell Q&A getting computer information

This topic contains 5 replies, has 4 voices, and was last updated by

 
Participant
3 years, 5 months ago.

  • Author
    Posts
  • #29896

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

  • #29908

    Participant
    Points: 41
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member
    $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.

The topic ‘getting computer information’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort