?
Solved

Change Powershell Script Output Format

Posted on 2010-11-17
2
Medium Priority
?
901 Views
Last Modified: 2012-05-10
Hi there,

I´ve written a Powershell script that gives me back the installed OS, installed service pack, processor architecture and shows of SNMP installed or not. This script works for me so far, but the output in a textfile is not like I would need it to be (I want to import it to Excel).

Can someone point out what needs to be changed to get a good table-based output?
Code is attatched, the script is started as ./getos.ps1 >> "D:\testscript.txt"

Regards
Steffen

$arrComputers = get-Content -path "c:\servers.txt"

foreach ($strComputer in $arrComputers)
{
 $collItems = Get-WmiObject -class "Win32_OperatingSystem" -namespace "root\CIMV2" -computername $strComputer
 foreach ($objItem in $collItems)
 {
   "Computer Name: ;" + $strComputer
   "Operating System: ;" + $objItem.Caption
   "Servicepack: ;" + $objItem.ServicePackMajorVersion
   " "
 }
 
 $collSNMP = Get-WmiObject -class "Win32_service" -namespace "root\CIMV2" -computername $strComputer | Where-Object {$_.Name -eq "SNMP"}
 foreach ($objItem in $collSNMP)
 {
   "SNMP: ;" + $objItem.Name
   
  " "
 }
 
 $collProcArch = Get-WmiObject -class "Win32_processor" -namespace "root\CIMV2" -computername $strComputer | Select-Object Caption
 foreach ($objItem in $collProcArch)
 {
  "Architecture: ;" + $objItem.Caption
   }
  " " 
  "--------------------------------------------------------------"
}

Open in new window

0
Comment
Question by:SSR-IS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 34156338
This will give you a CSV file, which will pop open in Excel nicely enough.

HTH

Chris
Get-Content -path "c:\servers.txt" | ForEach-Object {

  $ComputerName = $_

  Get-WmiObject Win32_OperatingSystem -ComputerName $ComputerName | Select-Object `
    @{n='Computer Name';e={ $ComputerName }},
    @{n='Operating System';e={ $_.Caption }},
    @{n='Servicepack';e={ $_.ServicePackMajorVersion }},
    @{n='SNMP';e={ Get-WmiObject Win32_service -ComputerName $ComputerName -Filter "Name='SNMP'" | Select-Object -ExpandProperty Name }},
    @{n='Architecture';e={ Get-WmiObject Win32_Processor -ComputerName $ComputerName | Select-Object -ExpandProperty Caption }}

} | Export-Csv "testscript.csv" -NoTypeInformation

Open in new window

0
 

Author Closing Comment

by:SSR-IS
ID: 34162212
Thanks a lot Chris-Dent! Perfect output-file for my pruposes!
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question