Solved

need a powershell script to export server make and model and operating system to csv

Posted on 2015-02-19
7
128 Views
Last Modified: 2015-02-20
can someone provide a script that will key on an input .txt file and export the server make / model and o/s to a csv file?

thx in advance,
0
Comment
Question by:siber1
[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
  • 4
  • 2
7 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40620225
Use the below script to get all of the info.
$Computers = get-content "c:\filename.txt"
foreach ($computer in $computers) {
Get-WMIObject -Class Win32_ComputerSystem -ComputerName $Computer | select Name, Model, Manufacturer | Out-file "c:\filename.csv" -append
}

Open in new window


Will.
0
 

Author Comment

by:siber1
ID: 40620266
thanks Will, how can I also add the operating system value? I tried modifying with OperatingSystem but it did not pull the value.
0
 

Author Comment

by:siber1
ID: 40620283
also will, the output of this command does not render well in excel.

it outputs like this and I cannot copy out this data and move to another sheet


Name                                    Model                                   Manufacturer                          
----                                    -----                                   ------------                          
SysI2                                  PowerEdge 2950                          Dell Inc.                              



Name                                    Model                                   Manufacturer                          
----                                    -----                                   ------------                          
sysPT                                 PowerEdge 2950                          Dell Inc.                              



Name                                    Model                                   Manufacturer                          
----                                    -----                                   ------------
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40620346
What you need to do is open excel, click the top level column click the data tab, click text to columns and click next, and finish. This will put all of the data in its own columns (3).

Operating System is not a member of this cmdlet. You have to use Get-Adcomputer for that which is an entirely different cmdlet.

From there you will see the data presented nicely.

Will.
0
 

Author Comment

by:siber1
ID: 40620362
thanks but that still doesn't produce the output I need.

does anyone else have a way of writing these results correctly to an excel file?
i''ve seen it done correctly before using variables, also I need the OS value included.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40620533
Hi, try this code.

Regards,

Rob.

(Get-Content "c:\filename.txt") | ForEach {
    $CompInfo = Get-WMIObject -Query "Select Name,Model,Manufacturer from Win32_ComputerSystem" -ComputerName $_
    $OSInfo = Get-WMIObject -Query "Select Caption from Win32_OperatingSystem" -ComputerName $_
    $Prop = [Ordered]@{
        'Name'=$_
        'Model'=$CompInfo.Model
        'Manufacturer'=$CompInfo.Manufacturer
        'OperatingSystem'=$OSInfo.Caption
    }
    New-Object PsObject -Property $Prop
} | Export-CSV C:\filename.csv -NoTypeInformation

Open in new window

0
 

Author Closing Comment

by:siber1
ID: 40621220
excellent. thx Rob
exactly what I was looking for.

S.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Suggested Solutions

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 …
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
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…

710 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