Friday, February 24, 2017

Yet another inventory script...

Yes, I know, there are a ton of PowerShell inventory scripts out there.  None ever did exactly what I wanted them to.  So, I found one that was close and tweaked it to do what I needed it to do.  Below is the result (so far).

It can be run against a domain from any domain member.  It requires a credential file containing domain admin credentials.  If the cred file isn't found it prompts to create it.  You need Excel installed since the data is written to Excel.  I don't have a "save" command in this so you need to save it manually yourself after the run is complete.

<#==============================================================================
          File Name : Inventory2Excel.ps1
    Original Author : Kenneth C. Mazie (kcmjr AT kcmjr.com)
                    :
        Description : Inspects specified systems and pulls WMI data then writes it to Excel.
                    :
              Notes : Normal operation is with no command line options.  Requires an admin account
                    :   with a stored config file.  If it is not found you are prompted and one
                    :   is created that can be used in other scripts.
                    : Optional arguments:
                    :   -Debug $true (defaults to false. targets a single PC or short list)
                    :   -Console $true (displays runtime info on console)
                    :   -Mode xxx (defaults to "all".  Other options "wks" or "srv" to target workstations or servers.
                    :                  If debug is set then it over-rides this setting.)
                    : 
                    :
           Warnings : None
                    :  
              Legal : Public Domain. Modify and redistribute freely. No rights reserved.
                    : SCRIPT PROVIDED "AS IS" WITHOUT WARRANTIES OR GUARANTEES OF
                    : ANY KIND. USE AT YOUR OWN RISK. NO TECHNICAL SUPPORT PROVIDED.
                    :
           Credits : Code snippets and/or ideas came from many sources including but
                    :   not limited to the following:
                    :   Based on CompInv_v2.ps1 by Jesse Hamrick at www.powershellpro.com 2009.
                    :
     Last Update by : Kenneth C. Mazie
    Version History : v1.0 - 02-24-17 - Original
     Change History : v1.1 - 00-00-00
                    :
#===============================================================================#>
#requires -version 3.0

Param(
      [bool]$Debug = $False,
      [bool]$Console = $false,
      $Mode
)
     
If ($Debug){$Script:Debug = $true}
If ($Console){$Script:Console = $true}

Clear-host
Clear-Host
$ErrorActionPreference = "SilentlyContinue"
$Console = $true

$AlphaHash = @{
"A:" = "3";
"B:" = "8";
"C:" = "13";
"D:" = "18";
"E:" = "23";
"F:" = "28";
"G:" = "33";
"H:" = "38";
"I:" = "43";
"J:" = "48";
"K:" = "53";
"L:" = "58";
"M:" = "63";
"N:" = "68";
"O:" = "73";
"P:" = "78";
"Q:" = "83";
"R:" = "88";
"S:" = "93";
"T:" = "98";
"U:" = "103";
"V:" = "108";
"W:" = "113";
"X:" = "118";
"Y:" = "123";
"Z:" = "128"
}

function get-productkey{
      $Reg = [WMIClass] ("\\" + $Script:Target + "\root\default:StdRegProv")
      $values = [byte[]]($reg.getbinaryvalue(2147483650,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId").uvalue)
      $lookup = [char[]]("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")
      $keyStartIndex = [int]52;
      $keyEndIndex = [int]($keyStartIndex + 15);
      $decodeLength = [int]29
      $decodeStringLength = [int]15
      $decodedChars = new-object char[] $decodeLength
      $hexPid = new-object System.Collections.ArrayList
      for ($i = $keyStartIndex; $i -le $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }
      for ( $i = $decodeLength - 1; $i -ge 0; $i--){
     if (($i + 1) % 6 -eq 0){
                  $decodedChars[$i] = '-'
            }else{
            $digitMapIndex = [int]0
            for ($j = $decodeStringLength - 1; $j -ge 0; $j--){
                  $byteValue = [int](($digitMapIndex * [int]256) -bor [byte]$hexPid[$j]);
                  $hexPid[$j] = [byte] ([math]::Floor($byteValue / 24));
                  $digitMapIndex = $byteValue % 24;
                  $decodedChars[$i] = $lookup[$digitMapIndex];
            }
        }
    }
      $STR = ''    
      $decodedChars | % { $str+=$_}
      Return $STR
}

Function WMILookup {
      If ((oddoreven $Script:Row) -eq "Odd"){$RowColorIndex = 15}
     
      Try{
            If ($Console){Write-Host "  -- Probing for System Info..." -ForegroundColor Yellow}
            $GenItems1 = gwmi Win32_ComputerSystem -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for Operating System Info..." -ForegroundColor Yellow}
            $GenItems2 = gwmi Win32_OperatingSystem -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for BIOS Info..." -ForegroundColor Yellow}
            $SysItems1 = gwmi Win32_BIOS -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for System Time Info..." -ForegroundColor Yellow}
            $SysItems2 = gwmi Win32_TimeZone -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for WMI Info..." -ForegroundColor Yellow}
            $SysItems3 = gwmi Win32_WmiSetting -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for CPU Info..." -ForegroundColor Yellow}
            $ProcItems1 = gwmi Win32_Processor -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for Memory Info..." -ForegroundColor Yellow}
            $MemItems1 = gwmi Win32_PhysicalMemory -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for Detailed Memory Info..." -ForegroundColor Yellow}
            $memItems2 = gwmi Win32_PhysicalMemoryArray -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for Disk Info..." -ForegroundColor Yellow}
            $DiskItems = gwmi Win32_LogicalDisk -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop
            If ($Console){Write-Host "  -- Probing for Network Info..." -ForegroundColor Yellow}
            $NetItems = gwmi Win32_NetworkAdapterConfiguration -Comp $Script:Target -Credential $Script:Credential -ErrorAction Stop | where{$_.IPEnabled -eq "True"}
            If ($Console){Write-Host "  -- Probing for Product Key..." -ForegroundColor Yellow}
            $ProdKey = Get-ProductKey
      }Catch{
            $ErrorMessage = $_.Exception.Message
      $FailedItem = $_.Exception.ItemName
            If ($Console){Write-host "    -- WMI Error: $ErrorMessage $FailedItem" -ForegroundColor Red}
            foreach ($Item in $SheetList){
                  $Item.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
                  $Item.Cells.Item($Script:Row, 1) = $Script:Target
                  $Item.Cells.Item($Script:Row, 2) = $ErrorMessage
                  $Item.Cells.Item($Script:Row, 2).Font.ColorIndex = 30
                  $Item.Cells.Item($Script:Row, 2).Font.Bold = $true
            }    
            return
      }    
                       
      #--[ Populate General Data ]-------------------------------------------------
      foreach ($objItem in $GenItems1){
            Switch($objItem.DomainRole){
                  0{$Sheet1.Cells.Item($Script:Row, 3) = "Stand Alone Workstation"}
                  1{$Sheet1.Cells.Item($Script:Row, 3) = "Member Workstation"}
                  2{$Sheet1.Cells.Item($Script:Row, 3) = "Stand Alone Server"}
                  3{$Sheet1.Cells.Item($Script:Row, 3) = "Member Server"}
                  4{$Sheet1.Cells.Item($Script:Row, 3) = "Back-up Domain Controller"}
                  5{$Sheet1.Cells.Item($Script:Row, 3) = "Primary Domain Controller"}
                  default{"Undetermined"}
            }
            $Sheet1.Cells.Item($Script:Row, 4) = $objItem.Manufacturer
            $Sheet1.Cells.Item($Script:Row, 5) = $objItem.Model
            $Sheet1.Cells.Item($Script:Row, 6) = $objItem.SystemType
            $Sheet1.Cells.Item($Script:Row, 7) = $objItem.NumberOfProcessors
            $Sheet1.Cells.Item($Script:Row, 8) = $objItem.TotalPhysicalMemory / 1024 / 1024
      }
      foreach ($objItem in $GenItems2){
            $Sheet1.Cells.Item($Script:Row, 9) = $objItem.Caption
            $Sheet1.Cells.Item($Script:Row, 10) = $objItem.csdversion
      }
      $Sheet1.Cells.Item($Script:Row, 11) = $ProdKey
           
      $Sheet1.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
      [Void]$Sheet1.UsedRange.EntireColumn.AutoFit() 
                 
      #--[ Populate Systems Data ]------------------------------------------------
      foreach ($objItem in $SysItems1){
            $Sheet2.Cells.Item($Script:Row, 1) = $Script:Target
            $Sheet2.Cells.Item($Script:Row, 3) = $objItem.Name
            $Sheet2.Cells.Item($Script:Row, 4) = $objItem.SMBIOSbiosVersion
            $Sheet2.Cells.Item($Script:Row, 5) = $objItem.SerialNumber
            }
      foreach ($objItem in $SysItems2){  
            $Sheet2.Cells.Item($Script:Row, 6) = $objItem.Caption
            }
      foreach ($objItem in $SysItems3){
            $Sheet2.Cells.Item($Script:Row, 7) = $objItem.BuildVersion
            }
      $Sheet2.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
      [Void]$Sheet2.UsedRange.EntireColumn.AutoFit()
                       
      #--[ Populate Processor Data ]----------------------------------------------
      $Count1 = 2
      $Sheet3.Cells.Item($Script:Row, 1) = $Script:Target

      foreach ($objItem in $ProcItems1){
            $Count1++
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.DeviceID+" "+$objItem.Name
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.Description
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.family
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.currentClockSpeed
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.l2cacheSize
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.UpgradeMethod
            $Sheet3.Cells.Item($Script:Row, $Count1++) = $objItem.SocketDesignation
      }
      $Sheet3.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
      [Void]$Sheet3.UsedRange.EntireColumn.AutoFit()
                       
      #--[ Populate Memory Data ]-------------------------------------------------
      $bankcounter = 1
      $Count1 = 2
      $Sheet4.Cells.Item($Script:Row, 1) = $Script:Target
      foreach ($objItem in $memItems2){
            $MemSlots = $objItem.MemoryDevices +1
            foreach ($objItem in $MemItems1){
                  $Count1++
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = "Bank " +$bankcounter
                  if($objItem.BankLabel -eq ""){
                        $Sheet4.Cells.Item($Script:Row, $Count1++) = $objItem.DeviceLocator
                  }Else{
                        $Sheet4.Cells.Item($Script:Row, $Count1++) = $objItem.BankLabel
                  }
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = $objItem.Capacity/1024/1024
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = $objItem.FormFactor
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = $objItem.TypeDetail
                  $bankcounter++
            }
            while($bankcounter -lt $MemSlots){
                  $Count1++
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = "Bank " +$bankcounter
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = "is Empty"
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = ""
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = ""
                  $Sheet4.Cells.Item($Script:Row, $Count1++) = ""
                  $bankcounter++
            }
      }
      $Sheet4.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
      [Void]$Sheet4.UsedRange.EntireColumn.AutoFit() 
                 
      #--[ Populate Disk Data ]---------------------------------------------------
      $Count1 = 2
      $Sheet5.Cells.Item($Script:Row, 1) = $Script:Target
      foreach ($objItem in $DiskItems){
            $Count1++
            [int]$Count1 = $AlphaHash.($objItem.DeviceID)
            If (($objItem.DriveType -ge 2) -or ($objItem.DriveType -le 5)){
                  Switch($objItem.DriveType){
                        2{$Sheet5.Cells.Item($Script:Row, $Count1++) = "Floppy"}
                        3{$Sheet5.Cells.Item($Script:Row, $Count1++) = "Fixed Disk"}
                        5{$Sheet5.Cells.Item($Script:Row, $Count1++) = "Removable Media"}
                        default{"Undetermined"}
                  }
                  $Sheet5.Cells.Item($Script:Row, $Count1++) = $objItem.DeviceID
                  $Sheet5.Cells.Item($Script:Row, $Count1++) = $objItem.Size/1024/1024
                  $Sheet5.Cells.Item($Script:Row, $Count1++) = $objItem.FreeSpace/1024/1024
            }Else{
                  $Count1 = $Count1+5
            }
      }
      $Sheet5.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
      [Void]$Sheet5.UsedRange.EntireColumn.AutoFit()
           
      #--[ Populate Network Data ]------------------------------------------------
      $Count1 = 2
      $Sheet6.Cells.Item($Script:Row, 1) = $Script:Target
      foreach ($objItem in $NetItems){
            $Count1++
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.Caption+" (enabled)"
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.DHCPEnabled
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.IPAddress
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.IPSubnet
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.DefaultIPGateway
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.DNSServerSearchOrder
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.FullDNSRegistrationEnabled
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.WINSPrimaryServer
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.WINSSecondaryServer
            $Sheet6.Cells.Item($Script:Row, $Count1++) = $objItem.WINSEnableLMHostsLookup
      }
      $Sheet6.Cells($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
      [Void]$Sheet6.UsedRange.EntireColumn.AutoFit()
}

function OddOrEven([long]$n){
      if (0,2,4,6,8 -contains "$n"[-1]-48){
      "Even"
      }else{
      "Odd"
      }
}

#--[ End of Functions ]---------------------------------------------------------

clear-host
$out = Get-PSSnapin | Where-Object {$_.Name -like "vmware.vimautomation.core"};if ($out -eq $null) {Add-PSSnapin vmware.vimautomation.core}

If ($Console){Write-Host "--[ Importing / Creating Credentials ]".padright(80, "-") -ForegroundColor Cyan}
$CredFile = "c:\pscreds.txt"
#$CredFile = Get-ChildItem -Path "c:\" -Filter "pscreds.txt" -Recurse | Select-Object -First 1   #--[ Can be used to scan for file ]--
If (!(Test-Path $CredFile -PathType Leaf )){
      If ($Console){Write-Host "  -- Creating new persistent Credential File..." -ForegroundColor Yellow }
      New-Object System.Management.Automation.PSCredential((Read-Host "Persistent Credential file not found.  Enter a user name"), (ConvertTo-SecureString -AsPlainText -Force (Read-Host "Enter a password"))) | Export-CliXml $CredFile
}
$Script:Credential = import-clixml -path "C:\pscreds.txt"
$domain = (Get-ADDomain).DNSroot
$user = $Script:Credential.UserName.Split("\")[1]
$pass = $Script:Credential.GetNetworkCredential().password

If ($Console){Write-Host "--[ Preparing Spreadsheet ]".padright(80, "-") -ForegroundColor Cyan}
#--[ Prep Excel ]---------------------------------------------------------------
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True

#--[ Generate required worksheets ]---------------------------------------------
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Excel.worksheets.item("Sheet4").Delete() | Out-Null

# --[ Variablize worksheets ]---------------------------------------------------
$Sheet1 = $Excel.Worksheets.Item(1)
$Sheet2 = $Excel.WorkSheets.Item(2)
$Sheet3 = $Excel.WorkSheets.Item(3)
$Sheet4 = $Excel.WorkSheets.Item(4)
$Sheet5 = $Excel.WorkSheets.Item(5)
$Sheet6 = $Excel.WorkSheets.Item(6)
$Sheet1.Name = "General"
$Sheet2.Name = "System"
$Sheet3.Name = "Processor"
$Sheet4.Name = "Memory"
$Sheet5.Name = "Disk"
$Sheet6.Name = "Network"

#--[ General Sheet Header ]-----------------------------------------------------
$Sheet1.Cells.Item(1,1) = "Target System"
$Sheet1.Cells.Item(1,3) = "Role"
$Sheet1.Cells.Item(1,4) = "HW Make"
$Sheet1.Cells.Item(1,5) = "HW Model"
$Sheet1.Cells.Item(1,6) = "HW Type"
$Sheet1.Cells.Item(1,7) = "CPU Count"
$Sheet1.Cells.Item(1,8) = "Memory MB"
$Sheet1.Cells.Item(1,9) = "Operating System"
$Sheet1.Cells.Item(1,10) = "SP Level"
$Sheet1.Cells.Item(1,11) = "Product Key"

#--[ System Sheet Header ]------------------------------------------------------
$Sheet2.Cells.Item(1,1) = "Target System"
$Sheet2.Cells.Item(1,3) = "BIOS Name"
$Sheet2.Cells.Item(1,4) = "BIOS Version"
$Sheet2.Cells.Item(1,5) = "HW Serial #"
$Sheet2.Cells.Item(1,6) = "Time Zone"
$Sheet2.Cells.Item(1,7) = "WMI Version"

#--[ Processor Sheet Header ]---------------------------------------------------
$Count1 = 2
$Sheet3.Cells.Item(1,1) = "Target System"
While ($Count1 -lt 60){
      $Count1++
      $Sheet3.Cells.Item(1,$Count1++) = "Processor"
      $Sheet3.Cells.Item(1,$Count1++) = "Type"
      $Sheet3.Cells.Item(1,$Count1++) = "Family"
      $Sheet3.Cells.Item(1,$Count1++) = "Speed MHz"
      $Sheet3.Cells.Item(1,$Count1++) = "Cache Size MB"
      $Sheet3.Cells.Item(1,$Count1++) = "Interface"
      $Sheet3.Cells.Item(1,$Count1++) = "Socket #"
}    

#--[ Memory Sheet Header ]------------------------------------------------------
$Sheet4.Cells.Item(1,1) = "Target System"
$Count1 = 2
$Count2 = 1
While ($Count1 -lt 55){
$Count1++
      $Sheet4.Cells.Item(1, $Count1++ ) = "Bank " + ($Count2)
      $Sheet4.Cells.Item(1, $Count1++ ) = "Label"
      $Sheet4.Cells.Item(1, $Count1++ ) = "Capacity MB"
      $Sheet4.Cells.Item(1, $Count1++ ) = "Form"
      $Sheet4.Cells.Item(1, $Count1++ ) = "Type"
      $Count2++
}

#--[ Disk Sheet Header ]--------------------------------------------------------
$Sheet5.Cells.Item(1,1) = "Target System"
$Count1 = 2
While ($Count1 -lt 52){
      $Count1++
      $Sheet5.Cells.Item(1,$Count1++) = "Disk Type"
      $Sheet5.Cells.Item(1,$Count1++) = "Drive Letter"
      $Sheet5.Cells.Item(1,$Count1++) = "Capacity MB"
      $Sheet5.Cells.Item(1,$Count1++) = "Free Space MB"
}    

#--[ Network Sheet Header ]-----------------------------------------------------
$Sheet6.Cells.Item(1,1) = "Target System"
$Count1 = 2
While ($Count1 -lt 40){
      $Count1++
      $Sheet6.Cells.Item(1,$Count1++) = "Network Card"
      $Sheet6.Cells.Item(1,$Count1++) = "DHCP Enabled"
      $Sheet6.Cells.Item(1,$Count1++) = "IP Address"
      $Sheet6.Cells.Item(1,$Count1++) = "Subnet Mask"
      $Sheet6.Cells.Item(1,$Count1++) = "Default Gateway"
      $Sheet6.Cells.Item(1,$Count1++) = "DNS Servers"
      $Sheet6.Cells.Item(1,$Count1++) = "DNS Reg"
      $Sheet6.Cells.Item(1,$Count1++) = "Primary WINS"
      $Sheet6.Cells.Item(1,$Count1++) = "Secondary WINS"
      $Sheet6.Cells.Item(1,$Count1++) = "WINS Lookup"
}

$SheetList = ($Sheet1, $Sheet2, $Sheet3, $Sheet4, $Sheet5, $Sheet6)
foreach ($Item in $SheetList){
      $Item.Cells(1, 1).EntireRow.Interior.ColorIndex = 56
      $Item.Cells(1, 1).EntireRow.Font.ColorIndex = 44
      $Item.Cells(1, 1).EntireRow.Font.Size = 14
      $Item.Cells(1, 1).EntireRow.Font.Bold = $true
      [Void]$Item.UsedRange.EntireColumn.AutoFit()
}

If ($Console){Write-Host "--[ Generating Target List ]".padright(80, "-") -ForegroundColor Cyan}
$Script:TargetList = ""

If ($Mode -eq "srv"){
      $Script:TargetList = Get-ADComputer -Properties * -Filter * | sort name | where {($_.name -NotLike "*esx*") -and ($_.operatingsystem -Like "*server*")} #--[ Servers only ]--
}ElseIF ($Mode -eq "wks"){
      $Script:TargetList = Get-ADComputer -Properties * -Filter * | sort name | where {($_.name -NotLike "*esx*") -and ($_.operatingsystem -NotLike "*server*")} #--[ Workstations only ]--
}Else{
      $Script:TargetList = Get-ADComputer -Properties * -Filter * | sort name | where {($_.name -NotLike "*esx*") -and ($_.operatingsystem -Like "*windows*")} #--[ All windows systems (unless debug enabled) ]--
}
If ($Debug){$Script:TargetList = Get-ADComputer -Properties * -Filter * | sort name | where {($_.name -Like "*-is*")} } #--[ Trumps all others if enabled ]--

$Script:Row = 2

foreach ($Script:Target in $Script:TargetList){
      $Script:Target = $Script:Target.name
      If ($Console){Write-host "`n--[ Processing: $Script:Target ]".PadRight(80, "-") -ForegroundColor Green}
      If (Test-Connection -ComputerName $Script:Target -count 1 -BufferSize 16 -ErrorAction SilentlyContinue ) {
            $Sheet1.Cells.Item($Script:Row, 1) = $Script:Target
            WMILookup
      }Else{
      If ($Console){Write-host "  -- No connection..." -ForegroundColor Red}
            $Count = 1
            If ((oddoreven $Script:Row-eq "Odd"){$RowColorIndex = 15}
            While ($Count -le $Excel.Worksheets.Count){
                  $Excel.Worksheets($Count).Cells.Item($Script:Row, 1).EntireRow.Interior.ColorIndex = $RowColorIndex
                  $Excel.Worksheets($Count).Cells.Item($Script:Row, 1) = $Script:Target
                  $Excel.Worksheets($Count).Cells.Item($Script:Row, 2) = "No Connection"
                  $Excel.Worksheets($Count).Cells.Item($Script:Row, 2).Font.ColorIndex = 30
                  $Excel.Worksheets($Count).Cells.Item($Script:Row, 2).Font.Bold = $true
            $Count++
            }    
      }
      $Script:Row++
}

If ($Console){Write-Host "`n--[ COMPLETED ]".padright(80, "-") -ForegroundColor Red}