?
Solved

Powershell wmi inventory script

Posted on 2012-09-09
8
Medium Priority
?
4,351 Views
Last Modified: 2012-09-13
Hi
I am looking for some help writing a powershell script that will inventory win2008 servers and merge or append all information into one file preferable .csv

I have pieced together the attached script but I am not sure how to get all of the information to append or merge into one file? Currently i have all the information going to separate .txt files.

Would also like know how to pull all servers from a text file instead of typing them in the
 -computername field and have the script poll multiple servers at a time?

Thanks

__



$Size = @{name="Size(GB)";expression={ "{0:N2}" -f ([double]$_.Size/1GB) }}
$FreeSpace = @{name="FreeSpace(GB)";expression={ "{0:N2}" -f ([double]$_.FreeSpace/1GB) }}
$Used=@{name="Used(GB)";expression={ "{0:N2}" -f (([double]$_.Size-[double]$_.FreeSpace)/1GB) }}
$PercentFree=@{name="PercentFree";expression={ "{0:N2}" -f ([double]$_.FreeSpace/[double]$_.Size) }}
$PercentUsed=@{name="PercentUsed";expression={ "{0:N2}" -f (([double]$_.Size-[double]$_.FreeSpace)/[double]$_.Size) }}

#Memory
Get-WmiObject Win32_ComputerSystem -comp vista-srv.company.pri | Select-Object DomainRole,Name,Model,TotalPhysicalMemory | out-file c:\scripts\output\ram.txt
#Disk
Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computerName vista-srv.company.pri,vm-srv.company.pri | Select-Object SystemName,DeviceID,VolumeName,$Size,$FreeSpace,$used,$PercentFree,$PercentUsed | out-file c:\scripts\output\disk.txt
#Processor
Get-WmiObject Win32_Processor -comp vista-srv.company.pri,vm-srv.company.pri | Select-Object Description,MaxClockSpeed,SystemName | out-file c:\scripts\output\process.txt
#Applications
Get-wmiobject Win32_Product -comp vista-srv.company.pri,vm-srv.company.pri | Sort-Object Name | Format-Table __Server,Name,Version,Vendor | out-file c:\scripts\output\apps.txt
#Server Roles & Features
Get-WmiObject Win32_ServerFeature -ComputerName vista-srv.company.pri,vm-srv.company.pri | Format-Table __Server,ID,Name -AutoSize | out-file c:\scripts\output\roles.txt
disk.txt
0
Comment
Question by:AC-D
  • 5
  • 2
8 Comments
 
LVL 3

Accepted Solution

by:
Akulsh earned 800 total points
ID: 38381284
PowershellPro website has a very nice script that can fully inventory servers and create an Excel sheet of the information.
http://www.powershellpro.com/powershell-forum/hardware/computer-inventory-script/#p186

Try it. It will be worth your time. By default, it works with Excel 2003, but can be made to work with other versions.
0
 

Author Comment

by:AC-D
ID: 38381328
Thanks for the quick response on my post. The script at the link you provided works pretty slick although it does not return the information I am looking for and I would also like the results in .csv text file as the systems I am inventorying are on an isolated network with out excel installed. Could you provide any help getting my script to work the way i described?
0
 
LVL 84

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 600 total points
ID: 38381809
first off use a get-content to get a list of computers
then use a foreach to go through the list of computers..

on the lines of
$Size = @{name="Size(GB)";expression={ "{0:N2}" -f ([double]$_.Size/1GB) }}
$FreeSpace = @{name="FreeSpace(GB)";expression={ "{0:N2}" -f ([double]$_.FreeSpace/1GB) }}
$Used=@{name="Used(GB)";expression={ "{0:N2}" -f (([double]$_.Size-[double]$_.FreeSpace)/1GB) }}
$PercentFree=@{name="PercentFree";expression={ "{0:N2}" -f ([double]$_.FreeSpace/[double]$_.Size) }}
$PercentUsed=@{name="PercentUsed";expression={ "{0:N2}" -f (([double]$_.Size-[double]$_.FreeSpace)/[double]$_.Size) }}
$computers = get-content "C:\Test\computers.txt"
foreach ($computer in $computers) {

$Memory = Get-WmiObject Win32_ComputerSystem -computername $computer | Select-Object DomainRole,Name,Model,TotalPhysicalMemory
$disk = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computerName $computer | Select-Object SystemName,DeviceID,VolumeName,$Size,$FreeSpace,$used,$PercentFree,$PercentUsed
$Processor = Get-WmiObject Win32_Processor -computername $computer | Select-Object Description,MaxClockSpeed,SystemName 
$Application = Get-wmiobject Win32_Product -computername $computer | Sort-Object Name
#Server Roles & Features
$roles = Get-WmiObject Win32_ServerFeature -ComputerName $computer
Write-Output $computer $memory $disk $Processor $Application $roles
}

Open in new window

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:AC-D
ID: 38382614
Thanks

How would you get the output to a text file in .csv format?
0
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 38385078
use export-csv cmdlet
0
 

Author Comment

by:AC-D
ID: 38385091
Could you give me the syntax to use at the end of the script you provided me?

I have tried a bunch of combinations with export-csv and | and can not get the desired results of all the information into one comma separated text file.
0
 

Author Comment

by:AC-D
ID: 38391246
Would someone be able to give me the syntax to use at the end of the script below?

I have tried a bunch of combinations with export-csv and | and can not get the desired results of all the information into one comma separated text file.


$Size = @{name="Size(GB)";expression={ "{0:N2}" -f ([double]$_.Size/1GB) }}
$FreeSpace = @{name="FreeSpace(GB)";expression={ "{0:N2}" -f ([double]$_.FreeSpace/1GB) }}
$Used=@{name="Used(GB)";expression={ "{0:N2}" -f (([double]$_.Size-[double]$_.FreeSpace)/1GB) }}
$PercentFree=@{name="PercentFree";expression={ "{0:N2}" -f ([double]$_.FreeSpace/[double]$_.Size) }}
$PercentUsed=@{name="PercentUsed";expression={ "{0:N2}" -f (([double]$_.Size-[double]$_.FreeSpace)/[double]$_.Size) }}
$computers = get-content "C:\Test\computers.txt"
foreach ($computer in $computers) {

$Memory = Get-WmiObject Win32_ComputerSystem -computername $computer | Select-Object DomainRole,Name,Model,TotalPhysicalMemory
$disk = Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computerName $computer | Select-Object SystemName,DeviceID,VolumeName,$Size,$FreeSpace,$used,$PercentFree,$PercentUsed
$Processor = Get-WmiObject Win32_Processor -computername $computer | Select-Object Description,MaxClockSpeed,SystemName 
$Application = Get-wmiobject Win32_Product -computername $computer | Sort-Object Name
#Server Roles & Features
$roles = Get-WmiObject Win32_ServerFeature -ComputerName $computer
Write-Output $computer $memory $disk $Processor $Application $roles
}

Open in new window

0
 

Author Closing Comment

by:AC-D
ID: 38396778
I could not get the export-csv to export all information correctly  into one text file. I ended up modifing the script posted by by: Akulsh
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

840 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