Solved

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

Posted on 2015-02-19
7
119 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

839 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