Solved

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

Posted on 2015-02-19
7
110 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

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.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

930 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

12 Experts available now in Live!

Get 1:1 Help Now