jpd1109

Computer Inventory using WMI and Powershell, v3.1

May 22nd, 2013
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ==============================================================================================
  2. #
  3. # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2007
  4. #
  5. # NAME: Server/Workstation Inventory (CompInv_v3.ps1)
  6. #
  7. # AUTHOR: Jesse Hamrick
  8. # DATE  : 2/25/2009
  9. # Web   : www.PowerShellPro.com
  10. # COMMENT: Script Inventories Computers and sends results to an excel file.
  11. #
  12. # Revision:  22 May 13
  13. # Comment: Incorporated my own and others suggestions:
  14. #          a) Include tabs for installed software, b) Roles and Features, and c) Scheduled tasks (user generated)
  15. #          b) Skip computers that cannot be accessed, and skip local computer ("0")
  16. #          c) Display the computer name being skipped or inventoried (whether accessible or not)
  17. #          d) When default switch action was "undetermined", write to Excel file instead of screen.
  18. #          e) Added compatibility for Excel 2010 and 2013.  (set culture to "us-en")
  19. #          f) Updated prompt for txt file dialog
  20. #          g) Added additional progress status messages (helpful for larger environments)
  21. # ==============================================================================================
  22.  
  23. # ==============================================================================================
  24. # Functions Section
  25. # ==============================================================================================
  26. # Function Name 'WMILookup' - Gathers info using WMI and places results in Excel
  27. # ==============================================================================================
  28. Function WMILookup {
  29. foreach ($StrComputer in $colComputers) {
  30.  
  31.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing ComputerSystem data" -id 1
  32.         $GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer
  33.  
  34.         # when inventorying all domain servers, this computer is ID'ed as "0".  Do not inventory this computer.
  35.         if($StrComputer -eq "0") {continue}
  36.  
  37.         # If unable to capture system info, computer is not accessbile.  Skip to next computer.
  38.         if(!$GenItems1){
  39.             Write-Host "$StrComputer not found" -ForegroundColor Red
  40.             continue
  41.         }
  42.  
  43.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing OperatingSystem data" -id 1
  44.         $GenItems2 = gwmi Win32_OperatingSystem -Comp $StrComputer
  45.  
  46.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing BIOS data" -id 1
  47.         $SysItems1 = gwmi Win32_BIOS -Comp $StrComputer
  48.  
  49.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing TimeZone data" -id 1
  50.         $SysItems2 = gwmi Win32_TimeZone -Comp $StrComputer
  51.  
  52.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing WMISetting data" -id 1
  53.         $SysItems3 = gwmi Win32_WmiSetting -Comp $StrComputer
  54.  
  55.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing Processor data" -id 1
  56.         $ProcItems1 = gwmi Win32_Processor -Comp $StrComputer
  57.  
  58.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing PhysicalMemory data" -id 1
  59.         $MemItems1 = gwmi Win32_PhysicalMemory -Comp $StrComputer
  60.  
  61.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing PhysicalMemoryArray data" -id 1
  62.         $memItems2 = gwmi Win32_PhysicalMemoryArray -Comp $StrComputer
  63.  
  64.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing LogicalDisk data" -id 1
  65.         $DiskItems = gwmi Win32_LogicalDisk -Comp $StrComputer
  66.  
  67.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing NetworkAdapterConfiguration data" -id 1
  68.         $NetItems = gwmi Win32_NetworkAdapterConfiguration -Comp $StrComputer | where{$_.IPEnabled -eq "True"}
  69.  
  70.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing Installed Product data" -id 1
  71.         $SoftwareItems = gwmi Win32_Product -Comp $StrComputer
  72.  
  73.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing Roles and Features data" -id 1
  74.         $FeaturesItems = gwmi Win32_ServerFeature -Comp $StrComputer
  75.  
  76.         Write-Progress -Activity "Getting Inventory" -status "$StrComputer - Capturing Scheduled Task data" -id 1
  77.         $TaskItems = Get-SchTasks -ComputerName $StrComputer | where {$_.ID -eq 'Author'}
  78.                
  79. # Populate General Sheet(1) with information
  80.  
  81.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing OperatingSystem data" -id 1
  82.     foreach ($objItem in $GenItems1){
  83.         $Sheet1.Cells.Item($intRow, 1) = $StrComputer
  84.         Switch($objItem.DomainRole)
  85.             {
  86.             0{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Workstation"}
  87.             1{$Sheet1.Cells.Item($intRow, 2) = "Member Workstation"}
  88.             2{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Server"}
  89.             3{$Sheet1.Cells.Item($intRow, 2) = "Member Server"}
  90.             4{$Sheet1.Cells.Item($intRow, 2) = "Back-up Domain Controller"}
  91.             5{$Sheet1.Cells.Item($intRow, 2) = "Primary Domain Controller"}
  92.             default{$Sheet1.Cells.Item($intRow, 2) = "Undetermined"}
  93.             }
  94.         $Sheet1.Cells.Item($intRow, 3) = $objItem.Manufacturer
  95.         $Sheet1.Cells.Item($intRow, 4) = $objItem.Model
  96.         $Sheet1.Cells.Item($intRow, 5) = $objItem.SystemType
  97.         $Sheet1.Cells.Item($intRow, 6) = $objItem.NumberOfProcessors
  98.         $Sheet1.Cells.Item($intRow, 7) = $objItem.TotalPhysicalMemory / 1024 / 1024
  99.         }
  100.  
  101.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing OperatingSystem data" -id 1
  102.     foreach ($objItem in $GenItems2){
  103.         $Sheet1.Cells.Item($intRow, 8) = $objItem.Caption
  104.         $Sheet1.Cells.Item($intRow, 9) = $objItem.csdversion
  105.         }
  106.            
  107. #Populate Systems Sheet
  108.  
  109.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing BIOS data" -id 1
  110.     foreach ($objItem in $SysItems1){
  111.         $Sheet2.Cells.Item($intRow, 1) = $StrComputer
  112.         $Sheet2.Cells.Item($intRow, 2) = $objItem.Name
  113.         $Sheet2.Cells.Item($intRow, 3) = $objItem.SMBIOSbiosVersion
  114.         $Sheet2.Cells.Item($intRow, 4) = $objItem.SerialNumber
  115.         }
  116.  
  117.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing TimeZone data" -id 1
  118.     foreach ($objItem in $SysItems2){  
  119.         $Sheet2.Cells.Item($intRow, 5) = $objItem.Caption
  120.         }
  121.  
  122.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing WMISetting data" -id 1
  123.     foreach ($objItem in $SysItems3){
  124.         $Sheet2.Cells.Item($intRow, 6) = $objItem.BuildVersion
  125.         }
  126.                
  127. #Populate Processor Sheet      
  128.  
  129.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing Processor data" -id 1  
  130.     foreach ($objItem in $ProcItems1){
  131.         $Sheet3.Cells.Item($intRowCPU, 1) = $StrComputer
  132.         $Sheet3.Cells.Item($intRowCPU, 2) = $objItem.DeviceID+" "+$objItem.Name
  133.         $Sheet3.Cells.Item($intRowCPU, 3) = $objItem.Description
  134.         $Sheet3.Cells.Item($intRowCPU, 4) = $objItem.family
  135.         $Sheet3.Cells.Item($intRowCPU, 5) = $objItem.currentClockSpeed
  136.         $Sheet3.Cells.Item($intRowCPU, 6) = $objItem.l2cacheSize
  137.         $Sheet3.Cells.Item($intRowCPU, 7) = $objItem.UpgradeMethod
  138.         $Sheet3.Cells.Item($intRowCPU, 8) = $objItem.SocketDesignation
  139.         $intRowCPU = $intRowCPU + 1
  140.         }
  141.                
  142. #Populate Memory Sheet
  143. $bankcounter = 1
  144.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing PhysicalMemoryArray data" -id 1
  145.     foreach ($objItem in $memItems2){
  146.         $MemSlots = $objItem.MemoryDevices +1
  147.            
  148.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing PhysicalMemory data" -id 1
  149.     foreach ($objItem in $MemItems1){
  150.         $Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
  151.         $Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
  152.     if($objItem.BankLabel -eq ""){
  153.         $Sheet4.Cells.Item($intRowMem, 3) = $objItem.DeviceLocator}
  154.     Else{$Sheet4.Cells.Item($intRowMem, 3) = $objItem.BankLabel}
  155.         $Sheet4.Cells.Item($intRowMem, 4) = $objItem.Capacity/1024/1024
  156.         $Sheet4.Cells.Item($intRowMem, 5) = $objItem.FormFactor
  157.         $Sheet4.Cells.Item($intRowMem, 6) = $objItem.TypeDetail
  158.         $intRowMem = $intRowMem + 1
  159.         $bankcounter = $bankcounter + 1
  160.         }
  161.     while($bankcounter -lt $MemSlots)  
  162.         {
  163.         $Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
  164.         $Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
  165.         $Sheet4.Cells.Item($intRowMem, 3) = "is Empty"
  166.         $Sheet4.Cells.Item($intRowMem, 4) = ""
  167.         $Sheet4.Cells.Item($intRowMem, 5) = ""
  168.         $Sheet4.Cells.Item($intRowMem, 6) = ""
  169.         $intRowMem = $intRowMem + 1
  170.         $bankcounter = $bankcounter + 1
  171.         }
  172.     }
  173.            
  174.            
  175. #Populate Disk Sheet
  176.  
  177.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing LogicalDisk data" -id 1
  178.     foreach ($objItem in $DiskItems){
  179.         $Sheet5.Cells.Item($intRowDisk, 1) = $StrComputer
  180.         Switch($objItem.DriveType)
  181.             {
  182.             2{$Sheet5.Cells.Item($intRowDisk, 2) = "Floppy"}
  183.             3{$Sheet5.Cells.Item($intRowDisk, 2) = "Fixed Disk"}
  184.             5{$Sheet5.Cells.Item($intRowDisk, 2) = "Removable Media"}
  185.             default{$Sheet5.Cells.Item($intRowDisk, 2) = "Undetermined"}
  186.             }
  187.         $Sheet5.Cells.Item($intRowDisk, 3) = $objItem.DeviceID
  188.         $Sheet5.Cells.Item($intRowDisk, 4) = $objItem.Size/1024/1024
  189.         $Sheet5.Cells.Item($intRowDisk, 5) = $objItem.FreeSpace/1024/1024
  190.         $intRowDisk = $intRowDisk + 1
  191.         }
  192.        
  193. #Populate Network Sheet
  194.  
  195.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing NetworkAdapterConfiguration data" -id 1
  196.     foreach ($objItem in $NetItems){
  197.         $Sheet6.Cells.Item($intRowNet, 1) = $StrComputer
  198.         $Sheet6.Cells.Item($intRowNet, 2) = $objItem.Caption+" (enabled)"
  199.         $Sheet6.Cells.Item($intRowNet, 3) = $objItem.DHCPEnabled
  200.         $Sheet6.Cells.Item($intRowNet, 4) = $objItem.IPAddress
  201.         $Sheet6.Cells.Item($intRowNet, 5) = $objItem.IPSubnet
  202.         $Sheet6.Cells.Item($intRowNet, 6) = $objItem.DefaultIPGateway
  203.         $Sheet6.Cells.Item($intRowNet, 7) = $objItem.DNSServerSearchOrder
  204.         $Sheet6.Cells.Item($intRowNet, 8) = $objItem.FullDNSRegistrationEnabled
  205.         $Sheet6.Cells.Item($intRowNet, 9) = $objItem.WINSPrimaryServer
  206.         $Sheet6.Cells.Item($intRowNet, 10) = $objItem.WINSSecondaryServer
  207.         $Sheet6.Cells.Item($intRowNet, 11) = $objItem.WINSEnableLMHostsLookup
  208.         $intRowNet = $intRowNet + 1
  209.         }
  210.  
  211. #Populate Software Inventory Sheet
  212.  
  213.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing Installed Product data" -id 1
  214.     foreach ($objItem in $SoftwareItems){
  215.         $Sheet7.Cells.Item($intRowSoftware, 1) = $StrComputer
  216.         $Sheet7.Cells.Item($intRowSoftware, 2) = $objItem.Name
  217.         $Sheet7.Cells.Item($intRowSoftware, 3) = $objItem.Vendor
  218.         $Sheet7.Cells.Item($intRowSoftware, 4) = $objItem.Version
  219.         $Sheet7.Cells.Item($intRowSoftware, 5) = $objItem.IdentifyingNumber
  220.         $intRowSoftware = $intRowSoftware + 1
  221.         }      
  222.  
  223. #Populate Roles and Features Sheet
  224.  
  225.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing Roles and Features data" -id 1
  226.     foreach ($objItem in $FeaturesItems){
  227.         $Sheet8.Cells.Item($intRowFeature, 1) = $StrComputer
  228.         $Sheet8.Cells.Item($intRowFeature, 2) = $objItem.Name
  229.         $intRowFeature = $intRowFeature + 1
  230.         }      
  231.  
  232. #Populate Scheduled Tasks Sheet
  233.  
  234.     Write-Progress -Activity "Writing Inventory" -status "$StrComputer - Writing Scheduled Task data" -id 1
  235.     foreach ($objItem in $TaskItems){
  236.         $Sheet9.Cells.Item($intRowTask, 1) = $StrComputer
  237.         $Sheet9.Cells.Item($intRowTask, 2) = $objItem.ID
  238.         $Sheet9.Cells.Item($intRowTask, 3) = $objItem.Name
  239.         $Sheet9.Cells.Item($intRowTask, 4) = $objItem.Command
  240.         $Sheet9.Cells.Item($intRowTask, 5) = $objItem.Arguments
  241.         $Sheet9.Cells.Item($intRowTask, 6) = $objItem.Enabled
  242.         $Sheet9.Cells.Item($intRowTask, 7) = $objItem.StartDateTime
  243.         $Sheet9.Cells.Item($intRowTask, 8) = $objItem.DayInterval
  244.         $Sheet9.Cells.Item($intRowTask, 9) = $objItem.TimeLimit
  245.         $Sheet9.Cells.Item($intRowTask, 10) = $objItem.RunAsAccount
  246.         $Sheet9.Cells.Item($intRowTask, 11) = $objItem.RunLevel
  247.         $Sheet9.Cells.Item($intRowTask, 12) = $objItem.Location
  248.         $intRowTask = $intRowTask + 1
  249.         }      
  250.  
  251. $intRow = $intRow + 1
  252. $intRowCPU = $intRowCPU + 1
  253. $intRowMem = $intRowMem + 1
  254. $intRowDisk = $intRowDisk + 1
  255. $intRowNet = $intRowNet + 1
  256. $intRowSoftware = $intRowSoftware + 1
  257. $intRowFeature = $intRowFeature + 1
  258. $intRowTask = $intRowTask + 1
  259. }
  260. }
  261.  
  262.  
  263.  
  264. # ========================================================================
  265. # Function Name Get-SchTasks
  266. # Example use:
  267. # $tasks = Get-SchTasks -ComputerName servername | where {$_.ID -eq 'Author'}
  268. # ========================================================================
  269.  
  270. function Get-SchTasks{
  271.     Param(
  272.         [Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyname=$True)]
  273.         $ComputerName = $Env:ComputerName
  274.         )
  275. [xml]$SchTasks = schtasks /query /XML ONE /S $ComputerName
  276. $Tasks = $SchTasks.Tasks.Task
  277. $Tasks | %{
  278.     $TaskURI = $_.RegistrationInfo.URI
  279.     if ($TaskURI -ne $null ) {
  280.         $Name = Split-Path $TaskURI -Leaf;
  281.         $Location = Split-Path $TaskURI -Parent;
  282.     }
  283.     else
  284.     {
  285.     $Name = $null
  286.     $Location = $null
  287.     }
  288.    
  289.     New-Object PSObject -Property @{
  290.         ID = $_.Principals.Principal.ID
  291.         Name = $Name
  292.         Command = $_.Actions.Exec.Command
  293.         Arguments = $_.Actions.Exec.Arguments
  294.         Enabled = $_.Settings.Enabled
  295.         StartDateTime = $_.Triggers.CalendarTrigger.StartBoundary
  296.         DayInterval = $_.Triggers.CalendarTrigger.ScheduleByDay.DaysInterval
  297.         TimeLimit = $_.Settings.ExecutionTimeLimit
  298.         RunAsAccount = $_.Principals.Principal.UserID
  299.         RunLevel = $_.Principals.Principal.RunLevel
  300.         Location = $Location
  301.         }
  302.     }
  303. }
  304.  
  305.  
  306. # =============================================================================================
  307. # Function Name 'ListComputers' - Enumerates ALL computer objects in AD
  308. # ==============================================================================================
  309. Function ListComputers {
  310. $strCategory = "computer"
  311.  
  312. $objDomain = New-Object System.DirectoryServices.DirectoryEntry
  313.  
  314. $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
  315. $objSearcher.SearchRoot = $objDomain
  316. $objSearcher.Filter = ("(objectCategory=$strCategory)")
  317.  
  318. $colProplist = "name"
  319. foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
  320.  
  321. $colResults = $objSearcher.FindAll()
  322.  
  323. foreach ($objResult in $colResults)
  324.     {$objComputer = $objResult.Properties; $objComputer.name}
  325. }
  326.  
  327. # ==============================================================================================
  328. # Function Name 'ListServers' - Enumerates ALL Servers objects in AD
  329. # ==============================================================================================
  330. Function ListServers {
  331. $strCategory = "computer"
  332. $strOS = "Windows*Server*"
  333.  
  334. $objDomain = New-Object System.DirectoryServices.DirectoryEntry
  335.  
  336. $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
  337. $objSearcher.SearchRoot = $objDomain
  338. $objSearcher.Filter = ("(&(objectCategory=$strCategory)(OperatingSystem=$strOS))")
  339.  
  340. $colProplist = "name"
  341. foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
  342.  
  343. $colResults = $objSearcher.FindAll()
  344.  
  345. foreach ($objResult in $colResults)
  346.     {$objComputer = $objResult.Properties; $objComputer.name}
  347. }
  348.  
  349. #
  350. # ========================================================================
  351. # Function Name Select-FileDialog #
  352. # Created by Hugo Peeters #
  353. # http://www.peetersonline.nl #
  354. ###############################
  355.  
  356. # Example use:
  357. # $file = Select-FileDialog -Title "Select a file" -Directory "D:\scripts" -Filter "Powershell Scripts|(*.ps1)"
  358.  
  359. function Select-FileDialog
  360. {
  361. param([string]$Title,[string]$Directory,[string]$Filter)
  362. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
  363. $objForm = New-Object System.Windows.Forms.OpenFileDialog
  364. $objForm.InitialDirectory = $Directory
  365. $objForm.Filter = $Filter
  366. $objForm.Title = $Title
  367. $Show = $objForm.ShowDialog()
  368. If ($Show -eq "OK")
  369. {
  370. Return $objForm.FileName
  371. }
  372. Else
  373. {
  374. Write-Error "Operation cancelled by user."
  375. }
  376. }
  377. #
  378.  
  379. # ========================================================================
  380. # Function Name 'ListTextFile' - Enumerates Computer Names in a text file
  381. # Create a text file and enter the names of each computer. One computer
  382. # name per line. Supply the path to the text file when prompted.
  383. # ========================================================================
  384. Function ListTextFile {
  385.     $strText = Select-FileDialog -Title "Select a file" -Directory "c:" -Filter "Text Files (*.txt)|*.txt"
  386.     $colComputers = Get-Content $strText
  387. }
  388.  
  389. # ========================================================================
  390. # Function Name 'SingleEntry' - Enumerates Computer from user input
  391. # ========================================================================
  392. Function ManualEntry {
  393.     $colComputers = Read-Host "Enter Computer Name or IP"
  394. }
  395.  
  396.  
  397.  
  398. # ==============================================================================================
  399. # Script Body
  400. # ==============================================================================================
  401. $erroractionpreference = "SilentlyContinue"
  402.  
  403.  
  404. #Gather info from user.
  405. Write-Host "********************************"   -ForegroundColor Green
  406. Write-Host "Computer Inventory Script"          -ForegroundColor Green
  407. Write-Host "By: Jesse Hamrick"                  -ForegroundColor Green
  408. Write-Host "Created: 04/15/2009"                -ForegroundColor Green
  409. Write-Host "Contact: www.PowerShellPro.com"     -ForegroundColor Green
  410. Write-Host "********************************"   -ForegroundColor Green
  411. Write-Host " "
  412. Write-Host "Which computer resources would you like in the report?" -ForegroundColor Green
  413. $strResponse = Read-Host "[1] All Domain Computers, [2] All Domain Servers, [3] Computer names from a File, [4] Choose a Computer manually"
  414. If($strResponse -eq "1"){$colComputers = ListComputers | Sort-Object}
  415.     elseif($strResponse -eq "2"){$colComputers = ListServers | Sort-Object}
  416.     elseif($strResponse -eq "3"){. ListTextFile}
  417.     elseif($strResponse -eq "4"){. ManualEntry}
  418.     else{Write-Error "You did not supply a correct response, Please run script again." -foregroundColor Red}
  419. Write-Progress -Activity "Getting Inventory" -status "Running..." -id 1
  420.  
  421. #New Excel Application
  422. $culture = [System.Globalization.CultureInfo]"en-US"
  423. $oldCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture
  424. [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
  425. [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
  426. $Excel = New-Object -Com Excel.Application
  427. $Excel.visible = $True
  428.  
  429. # Create 9 worksheets
  430. $Excel = $Excel.Workbooks.Add()
  431. $Sheet = $Excel.Worksheets.Add()
  432. $Sheet = $Excel.Worksheets.Add()
  433. $Sheet = $Excel.Worksheets.Add()
  434. $Sheet = $Excel.Worksheets.Add()
  435. $Sheet = $Excel.Worksheets.Add()
  436. $Sheet = $Excel.Worksheets.Add()
  437. $Sheet = $Excel.Worksheets.Add()
  438. $Sheet = $Excel.Worksheets.Add()
  439.  
  440. # Assign each worksheet to a variable and
  441. # name the worksheet.
  442. $Sheet1 = $Excel.Worksheets.Item(1)
  443. $Sheet2 = $Excel.WorkSheets.Item(2)
  444. $Sheet3 = $Excel.WorkSheets.Item(3)
  445. $Sheet4 = $Excel.WorkSheets.Item(4)
  446. $Sheet5 = $Excel.WorkSheets.Item(5)
  447. $Sheet6 = $Excel.WorkSheets.Item(6)
  448. $Sheet7 = $Excel.WorkSheets.Item(7)
  449. $Sheet8 = $Excel.WorkSheets.Item(8)
  450. $Sheet9 = $Excel.WorkSheets.Item(9)
  451. $Sheet1.Name = "General"
  452. $Sheet2.Name = "System"
  453. $Sheet3.Name = "Processor"
  454. $Sheet4.Name = "Memory"
  455. $Sheet5.Name = "Disk"
  456. $Sheet6.Name = "Network"
  457. $Sheet7.Name = "Software"
  458. $Sheet8.Name = "Features"
  459. $Sheet9.Name = "Tasks"
  460.  
  461. #Create Heading for General Sheet
  462. $Sheet1.Cells.Item(1,1) = "Device_Name"
  463. $Sheet1.Cells.Item(1,2) = "Role"
  464. $Sheet1.Cells.Item(1,3) = "HW_Make"
  465. $Sheet1.Cells.Item(1,4) = "HW_Model"
  466. $Sheet1.Cells.Item(1,5) = "HW_Type"
  467. $Sheet1.Cells.Item(1,6) = "CPU_Count"
  468. $Sheet1.Cells.Item(1,7) = "Memory_MB"
  469. $Sheet1.Cells.Item(1,8) = "Operating_System"
  470. $Sheet1.Cells.Item(1,9) = "SP_Level"
  471.  
  472. #Create Heading for System Sheet
  473. $Sheet2.Cells.Item(1,1) = "Device_Name"
  474. $Sheet2.Cells.Item(1,2) = "BIOS_Name"
  475. $Sheet2.Cells.Item(1,3) = "BIOS_Version"
  476. $Sheet2.Cells.Item(1,4) = "HW_Serial_#"
  477. $Sheet2.Cells.Item(1,5) = "Time_Zone"
  478. $Sheet2.Cells.Item(1,6) = "WMI_Version"
  479.  
  480. #Create Heading for Processor Sheet
  481. $Sheet3.Cells.Item(1,1) = "Device_Name"
  482. $Sheet3.Cells.Item(1,2) = "Processor(s)"
  483. $Sheet3.Cells.Item(1,3) = "Type"
  484. $Sheet3.Cells.Item(1,4) = "Family"
  485. $Sheet3.Cells.Item(1,5) = "Speed_MHz"
  486. $Sheet3.Cells.Item(1,6) = "Cache_Size_MB"
  487. $Sheet3.Cells.Item(1,7) = "Interface"
  488. $Sheet3.Cells.Item(1,8) = "#_of_Sockets"
  489.  
  490. #Create Heading for Memory Sheet
  491. $Sheet4.Cells.Item(1,1) = "Device_Name"
  492. $Sheet4.Cells.Item(1,2) = "Bank_#"
  493. $Sheet4.Cells.Item(1,3) = "Label"
  494. $Sheet4.Cells.Item(1,4) = "Capacity_MB"
  495. $Sheet4.Cells.Item(1,5) = "Form"
  496. $Sheet4.Cells.Item(1,6) = "Type"
  497.  
  498. #Create Heading for Disk Sheet
  499. $Sheet5.Cells.Item(1,1) = "Device_Name"
  500. $Sheet5.Cells.Item(1,2) = "Disk_Type"
  501. $Sheet5.Cells.Item(1,3) = "Drive_Letter"
  502. $Sheet5.Cells.Item(1,4) = "Capacity_MB"
  503. $Sheet5.Cells.Item(1,5) = "Free_Space_MB"
  504.  
  505. #Create Heading for Network Sheet
  506. $Sheet6.Cells.Item(1,1) = "Device_Name"
  507. $Sheet6.Cells.Item(1,2) = "Network_Card"
  508. $Sheet6.Cells.Item(1,3) = "DHCP_Enabled"
  509. $Sheet6.Cells.Item(1,4) = "IP_Address"
  510. $Sheet6.Cells.Item(1,5) = "Subnet_Mask"
  511. $Sheet6.Cells.Item(1,6) = "Default_Gateway"
  512. $Sheet6.Cells.Item(1,7) = "DNS_Servers"
  513. $Sheet6.Cells.Item(1,8) = "DNS_Reg"
  514. $Sheet6.Cells.Item(1,9) = "Primary_WINS"
  515. $Sheet6.Cells.Item(1,10) = "Secondary_WINS"
  516. $Sheet6.Cells.Item(1,11) = "WINS_Lookup"
  517.  
  518. #Create Heading for Software Inventory Sheet
  519. $Sheet7.Cells.Item(1,1) = "Device_Name"
  520. $Sheet7.Cells.Item(1,2) = "Title"
  521. $Sheet7.Cells.Item(1,3) = "Vendor"
  522. $Sheet7.Cells.Item(1,4) = "Version"
  523. $Sheet7.Cells.Item(1,5) = "Identifying_Number"
  524.  
  525. #Create Heading for Roles and Features Sheet
  526. $Sheet8.Cells.Item(1,1) = "Device_Name"
  527. $Sheet8.Cells.Item(1,2) = "Role or Feature"
  528.  
  529. #Create Heading for Scheduled Tasks Sheet
  530. $Sheet9.Cells.Item(1,1) = "Device_Name"
  531. $Sheet9.Cells.Item(1,2) = "Job_Id"
  532. $Sheet9.Cells.Item(1,3) = "Name"
  533. $Sheet9.Cells.Item(1,4) = "Command"
  534. $Sheet9.Cells.Item(1,5) = "Arguments"
  535. $Sheet9.Cells.Item(1,6) = "Enabled"
  536. $Sheet9.Cells.Item(1,7) = "StartDateTime"
  537. $Sheet9.Cells.Item(1,8) = "DayInterval"
  538. $Sheet9.Cells.Item(1,9) = "TimeLimit"
  539. $Sheet9.Cells.Item(1,10) = "RunAsAccount"
  540. $Sheet9.Cells.Item(1,11) = "RunLevel"
  541. $Sheet9.Cells.Item(1,12) = "Location"
  542.  
  543. $colSheets = ($Sheet1, $Sheet2, $Sheet3, $Sheet4, $Sheet5, $Sheet6, $Sheet7, $Sheet8, $Sheet9)
  544. foreach ($colorItem in $colSheets){
  545. $intRow = 2
  546. $intRowCPU = 2
  547. $intRowMem = 2
  548. $intRowDisk = 2
  549. $intRowNet = 2
  550. $intRowSoftware = 2
  551. $intRowFeature = 2
  552. $intRowTask = 2
  553. $WorkBook = $colorItem.UsedRange
  554. $WorkBook.Interior.ColorIndex = 20
  555. $WorkBook.Font.ColorIndex = 11
  556. $WorkBook.Font.Bold = $True
  557. }
  558.  
  559. #Capture information for the selected devices
  560. WMILookup
  561.  
  562. #Auto Fit all sheets in the Workbook
  563. foreach ($colorItem in $colSheets){
  564.     $WorkBook = $colorItem.UsedRange                                                           
  565.     $WorkBook.EntireColumn.AutoFit()
  566.     clear
  567. }
  568.  
  569. Write-Host "*******************************" -ForegroundColor Green
  570. Write-Host "The Report has been completed."  -ForeGroundColor Green
  571. Write-Host "*******************************" -ForegroundColor Green
  572. # ========================================================================
  573. # END of Script
  574. # ========================================================================
Advertisement
Add Comment
Please, Sign In to add comment