Solved

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

Posted on 2015-02-19
7
116 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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. 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

Suggested Solutions

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This article runs through the process of deploying a single EXE application selectively to a group of user.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

773 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