From Evernote: |
Inventory Script - OS and Hardware |
# Add WMI ping first to make sure server is up and script can access system otherwise log to file as error and skip it. List of computers to inventory are defined in this variable: $colComputers = get-content C:\temp\input.txt. This script requires the use of the Quest AD snapin which is available on their site for free.
Add-PSSnapIn Quest.ActiveRoles.ADManagement
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
# Write out header row to Excel
$c.Cells.Item(1,1) = "Hostname"
$c.Cells.Item(1,2) = "CPUs"
$c.Cells.Item(1,3) = "Cores"
$c.Cells.Item(1,4) = "RAM(GB)"
$c.Cells.Item(1,5) = "Model"
$c.Cells.Item(1,6) = "SystemType"
$c.Cells.Item(1,7) = "Owner"
$c.Cells.Item(1,8) = "Roles"
$c.Cells.Item(1,9) = "Domain Role"
$c.Cells.Item(1,10) = "Domain"
$c.Cells.Item(1,11) = "OS"
$c.Cells.Item(1,12) = "OS Version"
$c.Cells.Item(1,13) = "Service Pack"
$c.Cells.Item(1,14) = "OS Directory"
$c.Cells.Item(1,15) = "Install Date"in
$c.Cells.Item(1,16) = "HW Manufacturer"
$c.Cells.Item(1,17) = "BIOS Name"
$c.Cells.Item(1,18) = "BIOS Version"
$c.Cells.Item(1,19) = "Serial Number"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$d.EntireColumn.AutoFit($True)
$intRow = 2
$colComputers = get-content C:\temp\input.txt
foreach ($strComputer in $colComputers)
{
$colCPUs = get-wmiobject Win32_processor -computername $strComputer
foreach ($objcpu in $colCPUs)
{
[int]$sockets = $sockets + 1
}
$c.Cells.Item($intRow, 1) = $strComputer.ToUpper()
$c.Cells.Item($intRow, 2) = $sockets
$colMems = get-wmiobject Win32_ComputerSystem -computername $strComputer| Select *
foreach ($objItem in $colmems)
{
$Role = Switch ($objItem.DomainRole) {
0 {"Standalone Workstation"}
1 {"Member Workstation"}
2 {"Standalone Server"}
3 {"Member Server"}
4 {"Backup Domain Controller"}
5 {"Primary Domain Controller"}
default {"Not a known Domain Role"}
}
$c.Cells.Item($intRow, 3) = $objItem.NumberOfProcessors
$c.Cells.Item($intRow, 4) = "{0:N0}" -f($objItem.TotalPhysicalMemory/1GB)
$c.Cells.Item($intRow, 5) = $objItem.Model
$c.Cells.Item($intRow, 6) = $objItem.SystemType
$c.Cells.Item($intRow, 7) = $objItem.PrimaryOwnerName
$c.Cells.Item($intRow, 8) = $objItem.Roles
$c.Cells.Item($intRow, 9) = $Role
$c.Cells.Item($intRow, 10) = $objItem.Domain
}
$colOS = get-wmiobject Win32_OperatingSystem -computername $strComputer| Select *
#$colOS = get-wmiobject Win32_OperatingSystem -computername $strComputer| Select Caption, InstallDate, SystemDirectory, Version, ServicePackMajorVersion, ServicePackMinorVersion
foreach ($objItem in $colOS)
{
$OSSP = [string]$objItem.ServicePackMajorVersion + "." + [string]$objItem.ServicePackMinorVersion
$c.Cells.Item($intRow, 11) = $objItem.Caption
$c.Cells.Item($intRow, 12) = $objItem.Version
$c.Cells.Item($intRow, 13) = $OSSP
$c.Cells.Item($intRow, 14) = $objItem.SystemDirectory
}
$os = get-wmiobject win32_operatingsystem -computername $strComputer
$c.Cells.Item($intRow, 15) = $os.ConvertToDateTime($os.InstallDate) -f "MM/dd/yyyy"
$colBIOS = get-wmiobject Win32_BIOS -computername $strComputer| Select *
#$colBIOS = get-wmiobject Win32_BIOS -computername $strComputer| Select Manufacturer, SMBIOSBIOSVersion, SerialNumber, Name
foreach ($objItem in $colBIOS)
{
$c.Cells.Item($intRow, 16) = $objItem.Manufacturer
$c.Cells.Item($intRow, 17) = $objItem.Name
$c.Cells.Item($intRow, 18) = $objItem.SMBIOSBIOSVersion
$c.Cells.Item($intRow, 19) = $objItem.SerialNumber
}
$intRow = $intRow + 1
$d.EntireColumn.AutoFit()
$sockets = 0
}
$d.EntireColumn.AutoFit()
$d.SaveAs('c:\Inventory.xlsx')
No comments:
Post a Comment