Solved

Change Powershell Script Output Format

Posted on 2010-11-17
2
899 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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export AD group members. 1 28
Ruby or Python 7 63
Find users who are in no AD group with Powershell 5 19
Fastest way to get file count in MS Server 2012 3 13
A procedure for exporting installed hotfix details of remote computers using powershell
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

730 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