Solved

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

Posted on 2015-02-19
7
108 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 53

Expert Comment

by:Will Szymkowski
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
excellent. thx Rob
exactly what I was looking for.

S.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now