Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:10:37+00:00 2026-06-15T08:10:37+00:00

im doing some testing with powershell to list hardware information of each computer in

  • 0

im doing some testing with powershell to list hardware information of each computer in my domain. my script will get a list of computer from a text file that i created using powershell.

$arrComputers = get-Content -Path "C:\powershell\List.txt"
foreach ($strComputer in $arrComputers)
{
    $colItemsOs = get-wmiobject -class "Win32_OperatingSystem" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsOs)
   {
    Write-host  "Computer Name: " $strComputer
    Write-host  "OsName: " $objItem.Name
    Write-host  "Version: " $objItem.Version
   }

    $colItemsCompsys = get-wmiobject -class "Win32_ComputerSystem" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsCompsys)
   {
    Write-host  "Memory: " $objItem.TotalPhysicalMemory
    Write-host  "Manufacturer: " $objItem.Manufacturer
    Write-host  "Model: " $objItem.Model
    Write-host  "Domain: " $objItem.Domain
   }



     $colItemsSysEnc = get-wmiobject -class "Win32_SystemEnclosure" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsSysEnc)
   {
    Write-host  "SerialNumber: " $objItem.SerialNumber
   }

     $colItemsProcessor = get-wmiobject -class "Win32_Processor" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsProcessor)
   {
    Write-host  "Processor: " $objItem.Name
   }

    $colItemsIP = get-wmiobject -class "Win32_NetworkAdapterConfiguration " -namespace "root\CIMV2" `
    -computername $strComputer -Filter "IpEnabled = TRUE"
   foreach ($objItem in $colItemsIP)
   {
    Write-host  "IPAddress: " $objItem.IpAddress
   }

    Write-host | Out-File c:\powershell\reportbeta.csv

}

however, i am unable to do so. how do i produce the result in csv file which will be able to be uploaded to my database using sqlcmd later on.

what am i missing out?

thank you


ive managed to display output in text file. however, only 1 record is displayed.

$arrComputers = get-Content -Path "C:\powershell\List.txt"
foreach ($strComputer in $arrComputers)
{
    $colItemsOs = get-wmiobject -class "Win32_OperatingSystem" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsOs)
   {
      $strComputer
      $Name =$objItem.Name
      $Version = $objItem.Version
   }

    $colItemsCompsys = get-wmiobject -class "Win32_ComputerSystem" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsCompsys)
   {
      $TotalMemory = $objItem.TotalPhysicalMemory
      $Manufacturer = $objItem.Manufacturer
      $Model = $objItem.Model
      $Domain = $objItem.Domain
   }



     $colItemsSysEnc = get-wmiobject -class "Win32_SystemEnclosure" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsSysEnc)
   {
      $SerialNUmber = $objItem.SerialNumber
   }

     $colItemsProcessor = get-wmiobject -class "Win32_Processor" -namespace "root\CIMV2" `
    -computername $strComputer
   foreach ($objItem in $colItemsProcessor)
   {
     $Processor = $objItem.Name
   }

    $colItemsIP = get-wmiobject -class "Win32_NetworkAdapterConfiguration " -namespace "root\CIMV2" `
    -computername $strComputer -Filter "IpEnabled = TRUE"
   foreach ($objItem in $colItemsIP)
   {
      $IPV4 = $objItem.IpAddress
   }

    $OutputObj  = New-Object -Type PSObject
    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $strComputer.ToUpper()


    $OutputObj | Add-Member -MemberType NoteProperty -Name Name -Value $Name 
    $OutputObj | Add-Member -MemberType NoteProperty -Name Version -Value $Version
    $OutputObj | Add-Member -MemberType NoteProperty -Name TotalPhysicalMemory -Value $TotalMemory 
    $OutputObj | Add-Member -MemberType NoteProperty -Name Manufacturer -Value $Manufacturer
    $OutputObj | Add-Member -MemberType NoteProperty -Name Model -Value $Model

    $OutputObj | Add-Member -MemberType NoteProperty -Name Processor -Value $ProcessorSpeed
    $OutputObj | Add-Member -MemberType NoteProperty -Name SerialNumber -Value $SerialNo
    $OutputObj | Add-Member -MemberType NoteProperty -Name Domain -Value $Domain
    $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPV4 
    $OutputObj | Export-CSV -NoTypeInformation "c:\powershell\report.txt"

}

im out of ideas now. should i make it into array like?

please advise.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:10:38+00:00Added an answer on June 15, 2026 at 8:10 am

    The problem is that you are exporting to csv within the loop, so the last item will be the only one showing. Try something like this.

    Before the loop:

    # Create empty array
    $report = @()
    

    At the end of the loop, in place of where you are currently exporting to CSV:

    #Add item to report
    $report += $OutputObj
    

    Finally, after the end of the loop:

    $report | Export-CSV -NoTypeInformation "c:\powershell\report.txt"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing some initial testing for a Rails app which will be deployed
I was doing some testing and i realized that the writer doesn't get automatically
I was doing some testing with some sites (that I will not mention), and
I am doing some testing in my iPhone app and I get this error:
I've just started doing some PowerShell scripting, and I'm running into a problem testing
Hi am doing some testing on the Freebase sandbox, but I can't get the
I am doing some testing on a new html5-css3 framework and I want to
I'm currently doing some testing to determine the performance implications of including an index
I am doing some testing for a very large website, created many different developers.
I was just doing some random testing on locking in multi-threading this morning and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.