Results 1 to 13 of 13
  1. #1
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts

    Still Trying to Master PowerShell

    Hey Y'all,

    Can anyone tell me why this code:
    Code:
    "Installed Programs:"
    
    $fmt = @{Expression={$_.DisplayName};Label="Program Name";width=30},
           @{Expression={$_.InstallDate};Label="Installed";width=9},
           @{Expression={$_.InstallLocation};Label="Install Path";width=41}
    
    if (!([Diagnostics.Process]::GetCurrentProcess().Path -match '\\syswow64\\'))
    {
      $unistallPath = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
      $unistallWow6432Path = `
        "\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
      @(
        if (Test-Path "HKLM:$unistallWow6432Path" ) { 
          Get-ChildItem "HKLM:$unistallWow6432Path"}
        if (Test-Path "HKLM:$unistallPath" ) { 
          Get-ChildItem "HKLM:$unistallPath" }
        if (Test-Path "HKCU:$unistallWow6432Path") { 
          Get-ChildItem "HKCU:$unistallWow6432Path"}
        if (Test-Path "HKCU:$unistallPath" ) { 
          Get-ChildItem "HKCU:$unistallPath" }
       ) |
      ForEach-Object { Get-ItemProperty $_.PSPath } |
      Where-Object {
        $_.DisplayName -and !$_.SystemComponent -and !$_.ReleaseType -and `
          !$_.ParentKeyName -and ($_.UninstallString -or $_.NoRemove)
      } |
      Sort-Object DisplayName |
      Select-Object DisplayName,InstallDate,InstallLocation | Format-Table $fmt
    }
    else
    {
      Write-Host `
        "You are running 32-bit Powershell on 64-bit system.`n" `
        'Please run 64-bit Powershell instead.'  -ForegroundColor Red
    }
    Runs just fine on Win 7 HP SP-1 but NOT on Win 8.1 Update 1 (both 64-bit).
    Using PowerShell 4.0 64-bit {Running AS Administrator}

    Win 8.1 Update 1 $PSVersionTable
    Code:
    PS> $PSVersionTable
    
    Name                           Value                                           
    ----                           -----                                           
    PSVersion                      4.0                                             
    WSManStackVersion              3.0                                             
    SerializationVersion           1.1.0.1                                         
    CLRVersion                     4.0.30319.34014                                 
    BuildVersion                   6.3.9600.17400                                  
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}                            
    PSRemotingProtocolVersion      2.2
    The only difference in the $PSVersionTable on the Win 7 machine is the last 5 digits of the CLRVersion which are 18444 and the last 5 digits of the BuildVersion which are 16406.

    I'm STUMPPED!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  2. #2
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,726
    Thanks
    147
    Thanked 156 Times in 149 Posts
    I've just run your code on my 8.1 - exactly the same details on the $PSVersionTable as you and it works. Well it gave me a list of installed programs. Of course, when I opened the Powershell ISE I ran the 32 bit one, and that didn't work - but at least it told me why!

    I notice that you didn't say what error messages there were or how it didn't work.....

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Access,

    Duh! Sorry about that!

    I get a whole page of this:
    Code:
    The property 'SystemComponent' cannot be found on this object. Verify that the 
    property exists.
    At line:24 char:5
    +     $_.DisplayName -and !$_.SystemComponent -and !$_.ReleaseType -and `
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
        + FullyQualifiedErrorId : PropertyNotFoundStrict
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Access & ALL,

    Well I solved this one but it still doesn't make sense to me!

    I has set: Set-StrictMode -Version Latest in my profile in response to a previous post about another problem. I remembered this last night while waiting to go to sleep (yeah I know I live a boring life!). Well I had decided to try it this morning but my better half had other plans (getting ready for tomorrow) so I just got to it. Setting: Set-StrictMode -off solved the problem. Why I don't know!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,593
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    Here's the TechNet page about Strice Mode - Set-StrictMode. Perhaps the answer is there.

    Joe

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Hey Y'all,

    Joe, Thanks for the link!

    Ok, I can see clearly now! Well at least for this issue.

    -Version<Version>

    Specifies the conditions that cause an error in strict mode. This parameter is required.

    The valid values are "1.0", "2.0", and "Latest". The following list shows the effect of each value.

    1.0 -- Prohibits references to uninitialized variables, except for uninitialized variables in strings.

    2.0 -- Prohibits references to uninitialized variables (including uninitialized variables in strings).
    -- Prohibits references to non-existent properties of an object.
    -- Prohibits function calls that use the syntax for calling methods.
    -- Prohibits a variable without a name (${}).

    Latest: -- Selects the latest (most strict) version available. Use this value to assure that scripts use the strictest available version, even when new versions are added to Windows PowerShell.

    Code:
    {5247E16E-BCF8-95AB-1653-B3F8F AuthorizedCDFPrefix :                           
    BF8B3F1}                       Comments            :                           
                                   Contact             :                           
                                   DisplayVersion      : 8.100.25984               
                                   HelpLink            :                           
                                   HelpTelephone       :                           
                                   InstallDate         : 20140825                  
                                   InstallLocation     :                           
                                   InstallSource       : C:\ProgramData\Package    
                                   Cache\{5247E16E-BCF8-95AB-1653-B3F              
                                                                                   
                                   8FBF8B3F1}v8.100.25984\Installers\              
                                   ModifyPath          : MsiExec.exe               
                                   /I{5247E16E-BCF8-95AB-1653-B3F8FBF8B3F1}        
                                   Publisher           : Microsoft Corporation     
                                   Readme              :                           
                                   Size                :                           
                                   EstimatedSize       : 1532                      
                                   SystemComponent     : 1    <-- Present Here!                     
                                   UninstallString     : MsiExec.exe               
                                   /I{5247E16E-BCF8-95AB-1653-B3F8FBF8B3F1}        
                                   URLInfoAbout        :                           
                                   URLUpdateInfo       :                           
                                   VersionMajor        : 8                         
                                   VersionMinor        : 100                       
                                   WindowsInstaller    : 1                         
                                   Version             : 140797312                 
                                   Language            : 1033                      
                                   DisplayName         : Windows Software          
                                   Development Kit DirectX x64 Remote              
    {5FCE6D76-F5DC-37AB-B2B8-22AB8 AuthorizedCDFPrefix :                           
    CEDB1D4}                       Comments            :                           
                                   Contact             :                           
                                   DisplayVersion      : 9.0.30729.6161            
                                   HelpLink            :                           
                                   HelpTelephone       :                           
                                   InstallDate         : 20141112                  
                                   InstallLocation     :                           
                                   InstallSource       :                           
                                   g:\87203c0a5accb74510368ee3e51179ac\            
                                   ModifyPath          : MsiExec.exe               
                                   /X{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}        
                                   NoModify            : 1                         
                                   NoRepair            : 1                         
                                   Publisher           : Microsoft Corporation     
                                   Readme              :                           
                                   Size                :                           
                                   EstimatedSize       : 13532      
                                                  <-- It ain't here! Causing the error!               
                                   UninstallString     : MsiExec.exe               
                                   /X{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}        
                                   URLInfoAbout        :                           
                                   URLUpdateInfo       :                           
                                   VersionMajor        : 9                         
                                   VersionMinor        : 0                         
                                   WindowsInstaller    : 1                         
                                   Version             : 151025673                 
                                   Language            : 1033                      
                                   DisplayName         : Microsoft Visual C++ 2008 
                                   Redistributable - x64
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,726
    Thanks
    147
    Thanked 156 Times in 149 Posts
    Glad you got it sorted, especially as I haven't a clue about the fix you found!

    I must look at Powershell more closely in the New Year.

    Happy Hols

  8. #8
    Lounger
    Join Date
    Dec 2009
    Location
    Gillingham, Dorset, UK
    Posts
    30
    Thanks
    0
    Thanked 13 Times in 11 Posts
    RG,

    This script should work, without setting 'Strictmode -off', by filtering on the properties before calling Get-Itemproperty.

    Code:
    Change:
    
      ForEach-Object { Get-ItemProperty $_.PSPath } |
      Where-Object {
        $_.DisplayName -and !$_.SystemComponent -and !$_.ReleaseType -and `
          !$_.ParentKeyName -and ($_.UninstallString -or $_.NoRemove)
      } |
    
    To:
    
    Where-Object {
      $_.GetValue('DisplayName') -and `
      ($_.GetValue('UninstallString') -or `
      $_.GetValue('NoRemove')) -and `
      !$_.GetValue('SystemComponent') -and `
      !$_.GetValue('ReleaseType') -and `
      !$_.GetValue('ParentKeyName')
    } |
    Get-ItemProperty |
    HTH & Regards

  9. The Following User Says Thank You to Cliff.H For This Useful Post:

    RetiredGeek (2015-01-15)

  10. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Cliff,

    Thanks, I'll give it a try. I'm currently on the road so I don't know when I'll get a chance to test this but I'll get back to you when I do.

    Thanks!
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  11. #10
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Cliff,

    Worked like a charm!

    Here's the entire program if anyone is interested.
    Code:
    <#
     +--------------------------------------------------------+
     | Computer Mentors System Information V6.9               |
     | Code adapted from:                                     |
     |          Powershell PC Info Script V1.0b               | 
     |             Coded By:Trenton Ivey(kno)                 | 
     |                    hackyeah.com                        |
     | Incorporated Coding changes recommed by Cafed00d @ WSL |
     | Updated:                                               |
     |   11/25/2013 - Add Network Adapter Info                |                                 
     |   01/11/2014 - Change Add-Row to use Param             | 
     |   08/14/2014 - Added Windows Product Key Func.         |  
     |   08/15/2014 - Added CPU values & Sorted Tables        |                              
     |   09/15/2014 - Added Shared Drives/Folders             | 
     |   09/17/2014 - Added Secure Boot UEFI status           | 
     |   10/10/2014 - Added CD/DVD Info                       |
     |   10/11/2014 - Added Mapped Drives w/error message,    |
     |                right align disk sizes                  | 
     |   10/26/2014 - Added selected Windows settings from    |
     |                the Registry                            |
     |   11/13/2014 - Added Hibernate Status to Win Settings  |  
     |   11/26/2014 - Added BIOS Date & Manufacturer          |
     |   12/23/2014 - Added Unique Driver Version Numbers     |  
     |   01/15/2015 - Incorporated code provided by: Cliff.H  |
     |                @WSL - removed the need for setting     |
     |                Set-StrictMode -Off                     |                       
     +--------------------------------------------------------+
    #>
    param (
      $compname = $env:COMPUTERNAME  #Default if no Compname Arg.
    )
    
     function Add-Row 
     {
      param (
             [string]$ItemName,
             [string]$ItemValue
            ) 
     
      #Create Row Variable 
          $CITRow = $CITable.NewRow()
      #Assign items to row variable
          $CITRow.Item = $ItemName
          $CITRow.Value = $ItemValue
      #Add Row to Table using Row Variable
          $CITable.Rows.Add($CITRow)
    }
    
    function get-windowsproductkey([string]$computer)
    {
     $Reg = [WMIClass] ("\\" + $computer + "\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+=$_}
     $STR
    }  #End Function get-windowsproductkey
    
    #-------   Main Program ------
    
    $enclosureNames = (
      "unknown",  # 0
      "Other" ,
      "Unknown" ,
      "Desktop" ,
      "Low Profile Desktop" ,
      "Pizza Box" ,  #5
      "Mini Tower" ,
      "Tower" ,
      "Portable" ,
      "Laptop" ,
      "Notebook" , #10
      "Hand Held" ,
      "Docking Station" ,
      "All-in-One" ,
      "Sub Notebook" ,
      "Space Saving" ,  #15
      "Lunch Box" ,
      "Main System Chassis",
      "Expansion Chassis",
      "Sub-Chassis",
      "Bus Expansion Chassis", #20
      "Peripheral Chassis" ,
      "Storage Chassis" ,
      "Rack Mount Chassis" ,
      "Sealed-Case PC" #24
    )
         
      Clear-Host
    
      "Computer Mentors Computer Information Version 6.9`n"
      
      "General Computer Information:"
    # Create Table
      $CITable = New-Object system.Data.DataTable "Computer Information"
    #Create Columns for table 
      $CITcol1 = New-Object system.Data.DataColumn Item,([string])       
      $CITcol2 = New-Object system.Data.DataColumn Value,([string])
    #Add Columns to table
      $CITable.columns.add($CITcol1)
      $CITable.columns.add($CITcol2)
    
      $ComputerSysObj = `
          get-WMIObject -computer $compname Win32_ComputerSystem    
    
      Add-Row -ItemName 'Computer Name'   -ItemValue $ComputerSysObj.Name 
      Add-Row -ItemName 'Current User ID' -ItemValue $ComputerSysObj.Username 
      Add-Row -ItemName 'Domain Name'     -ItemValue $ComputerSysObj.Domain 
      Add-Row -ItemName 'Manufacturer'    -ItemValue $ComputerSysObj.Manufacturer 
      Add-Row -ItemName 'Model'           -ItemValue $ComputerSysObj.Model
      Add-Row -ItemName 'System Type'     -ItemValue $ComputerSysObj.SystemType        
    
      $enclosure = get-wmiobject -computer $compname Win32_SystemEnclosure
      $ChassisNo = $enclosure.ChassisTypes[0]
      $ChassisName =  if ($ChassisNo -ge $enclosureNames.length) {
                             "Currently Unassigned"
                      } 
                      else {
                             $enclosureNames[$ChassisNo]
                      }
    
      Add-Row  -ItemName 'Enclosure' -ItemValue $ChassisName
      
      $BIOSObject = get-WMIObject -computer $compname Win32_BIOS
      Add-Row -ItemName 'BIOS Serial No'    -ItemValue $BIOSObject.SerialNumber
      Add-Row -ItemName '     Name'         -ItemValue $BIOSObject.Name
      Add-Row -ItemName '     Version'      -ItemValue $BIOSObject.SMBIOSBIOSVersion
      Add-Row -ItemName '     Date'         -ItemValue $BIOSObject.Version
      Add-ROw -ItemName '     Manufacturer' -ItemValue $BIOSObject.Manufacturer
    
      $ErrorActionPreference = 'SilentlyContinue'
      $UEFISB = Confirm-SecureBootUEFI
      $ErrorActionPreferenct = 'Continue'
      if ($UEFISB -ne $null) {
        if ($UEFISB) {$UEFIStatus="On"} Else {$UEFIStatus="OFF"}
      Add-Row -ItemName 'Secure Boot UEFI' `
              -ItemValue $UEFIStatus 
      }
      Else {
      Add-Row -ItemName 'Secure Boot UEFI' -ItemValue "Not Supported"
      }  
    
      Get-CimClass -PropertyName version -QualifierName dynamic | Out-Null
      $CurOS = Get-CimInstance Win32_OperatingSystem
      $OSKey = get-windowsproductkey $ComputerSysObj.name
      $OS_Object = get-WMIObject -computer $compname Win32_OperatingSystem
      $LocalDateTime = $OS_Object.ConvertToDateTime($OS_Object.LocalDateTime) 
      $LastBootUpTime = $OS_Object.ConvertToDateTime($OS_Object.LastBootUpTime)
      $UpTime = @([String]($LocalDateTime - $LastBootUpTime))
    
      Add-Row -ItemName 'OS Name'      -ItemValue $CurOS.Caption
      Add-Row -ItemName '   Version'   -ItemValue $CurOS.Version
      Add-Row -ItemName '   Bit-Width' -ItemValue $CurOS.OSArchitecture
      Add-Row -ItemName '   Key'       -ItemValue $OSKey  
      Add-Row -ItemName '   Time   '   -ItemValue $LocalDateTime
      Add-Row -ItemName '   Last Boot' -ItemValue $LastBootUpTime
      Add-Row -ItemName '   Up Time'   -ItemValue $UpTime.split('.')[0] 
    
      $CPU_Object = get-WMIObject -computer $compname Win32_Processor
    
      Add-Row -ItemName 'Processor Name'  -ItemValue $CPU_Object.Name
      Add-Row -ItemName '          Info'  -ItemValue $CPU_Object.Caption
      Add-Row -ItemName '         Maker'  -ItemValue $CPU_Object.Manufacturer
      Add-Row -ItemName '            ID'  -ItemValue $CPU_Object.ProcessorID
      Add-Row -ItemName 'Physical Cores'  -ItemValue $CPU_Object.NumberofCores
      Add-Row -ItemName 'Logical  Cores'  -ItemValue `
                                           $CPU_Object.NumberofLogicalProcessors
      Add-Row -ItemName ' Address Width'  -ItemValue $CPU_Object.AddressWidth
    
    #Output table -- General Computer Information:
      $fmt = @{Expression={$_.Item};Label="Item";width=20},
             @{Expression={$_.Value};Label="Value";Width=50}
                 
      $CITable | Select-Object Item,Value | Format-Table $fmt
    
    #Memory Info 
      "Memory Information:"
      $fmt = @{Expression={$_.Speed};Label="Speed";width=5},
             @{Expression={$_.DataWidth};Label="Data Width";width=10},
             @{Expression={ '{0:#.00}' -f ($_.Capacity/1gb)}; `
                               Label="Size / GB";width=9},
             @{Expression={$_.DeviceLocator};Label="Slot";width=6},
             @{Expression={$_.SerialNumber};Label="Serial No."}
    
      get-WMIObject -computer $compname Win32_PhysicalMemory | `
          Sort-Object {$_.DeviceLocator} | Format-Table $fmt
                
    #Disk Info 
      $fmt = @{Expression={$_.Name};Label="Drive Letter";width=6},
             @{Expression={$_.VolumeName};Label="Vol Name";Width=15},
             @{Expression={ '{0:#,000.00}' -f ($_.Size/1gb)}; `
                  Label="Disk Size`n / GB";width=9;align='right';},
             @{Expression={ '{0:#,000.00}' -f ($_.FreeSpace/1gb)}; `
                  Label="Free Space`n / GB";width=10;align='right';}
      "Drive Information:"
      get-WMIObject -computer $compname Win32_logicaldisk | `
         Where-Object {$_.size -ge 0 -and $_.ProviderName -eq $null } | `
         Format-Table $fmt
    
    #Mapped Drives Info
      $fmt = @{Expression={$_.Name};Label="Drive Letter";width=6},
             @{Expression={$_.Compressed};Label="Compressed";Width=5},
             @{Expression={$_.ProviderName};Label="Provider";Width=50},
             @{Expression={ '{0:#,000.00}' -f ($_.Size/1gb)}; `
                  Label="Disk Size`n / GB";width=9;align='right';}
      "Mapped Drive Information:"
      $MappedDrives = get-WMIObject -computer $compname Win32_MappedLogicalDisk | `
           Where-Object {$_.size -ge 0 -and $_.ProviderName -ne $null } 
      If ($MappedDrives.count -eq 0) {
        "`n--No Mapped Drives--"
        "If drives were mapped using standard user privileges, even from an"
        "administrator account, they will not show up if this script is run"
        "as Administrator!`n"
      }
      Else {
      $MappedDrives| Format-Table $fmt
      }
    
    #CD/DVD Info
      "CD/DVD Information:"
      $CD = Get-WmiObject Win32_CDROMDrive -ComputerName $compname 
      If ($CD -ne $null) {
        $fmt = @{Expression={$_.Drive};Label="Drive Letter";width=6},
               @{Expression={$_.Name};Label="Name";Width=25},
               @{Expression={$_.CapabilityDescriptions};Label="Capabilities";`
                             width=40}
        $CD |  Format-Table -wrap  $fmt
      }
      Else{
           "None-Avaliable"
      }
    #Shares Info
      $fmt = @{Expression={$_.Name};Label="Share Name";width=12},
             @{Expression={$_.PSComputerName};Label="Computer Name";Width=15},
             @{Expression={$_.Path};Label="Path";width=15},
             @{Expression={$_.MaximumAllowed};Label="Max Users";width=9}
             "Share Information:"
      Get-CimInstance –Class Win32_Share –ComputerName $compname | `
         Where-Object {$_.Type –eq 0} | Format-Table $fmt
    
    #Monitor Info 
      "Monitor Information:" 
      #Turn off Error Messages 
      $ErrorActionPreference_Backup = $ErrorActionPreference 
      $ErrorActionPreference = "SilentlyContinue" 
     
      $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine
             
      if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,"")){ 
         #Create Table To Hold Info 
         $montable = New-Object system.Data.DataTable "Monitor Info" 
         #Create Columns for Table 
         $moncol1 = New-Object system.Data.DataColumn Name,([string]) 
         $moncol2 = New-Object system.Data.DataColumn Serial,([string]) 
         $moncol3 = New-Object system.Data.DataColumn Ascii,([string]) 
         #Add Columns to Table 
         $montable.columns.add($moncol1) 
         $montable.columns.add($moncol2) 
         $montable.columns.add($moncol3) 
     
         $fmt = @{Expression={$_.Name};Label="Monitor Name";width=20},
                @{Expression={$_.Serial};Label="Serial Number";width=15},
                @{Expression={$_.Ascii};Label="Ascii";width=10}
     
         $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\DISPLAY" ) 
         $HID = $regkey.GetSubKeyNames() 
    
         foreach($HID_KEY_NAME in $HID){ 
           $regKey = `
       $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME")  
           $DID = $regkey.GetSubKeyNames() 
                        
           foreach($DID_KEY_NAME in $DID){ 
             $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME\\$DID_KEY_NAME\\Device Parameters" ) 
             $EDID = $regKey.GetValue("EDID") 
                          
             foreach($int in $EDID){ 
               $EDID_String = $EDID_String+([char]$int) 
             } 
                         
             #Create new row in table 
             $monrow=$montable.NewRow() 
                         
             #MonitorName 
             $checkstring = `
               [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00            
             $matchfound = $EDID_String -match "$checkstring([\w ]+)" 
             if($matchfound){
               $monrow.Name = [string]$matches[1]} 
             else {$monrow.Name = '-'} 
                              
             #Serial Number 
             $checkstring = `
                [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00            
             $matchfound =  $EDID_String -match "$checkstring(\S+)" 
             if($matchfound){
               $monrow.Serial = [string]$matches[1]} 
             else {$monrow.Serial = '-'} 
                                                  
             #AsciiString 
             $checkstring = `
                [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00            
             $matchfound = $EDID_String -match "$checkstring([\w ]+)" 
             if($matchfound){
               $monrow.Ascii = [string]$matches[1]} 
             else {$monrow.Ascii = '-'}          
                                   
             $EDID_String = '' 
                          
             $montable.Rows.Add($monrow) 
    
           }   # End - foreach($DID_KEY_NAME in $DID)
                        
         } # End - foreach($HID_KEY_NAME in $HID)
                    
                    $montable | select-object  -unique Serial,Name,Ascii | 
                       Where-Object {$_.Serial -ne "-"} | Format-Table $fmt
                     
      }   # End If
                
      else {  
             Write-Host "Access Denied - Check Permissions" 
      } 
    
    #Network Adapter Information
      "Network Information:" 
    
    if($OS_Object.Caption.Substring(0,19) -eq "Microsoft Windows 8") {
      $netfmt = @{Expression={ $_.Name};Label="Name";Width=35},
                @{Expression={$_.Status};Label="Status";Width=25}
    
      Get-NetAdapter -Name * | Format-Table $netfmt
    }
    Else {
        $fmtPCNetAdpts = `
           @{Expression={ $_.Description};Label="Adapter Name";Width=55}
        $PCNetAdpts = Get-WmiObject -Class Win32_NetworkAdapterConfiguration `
                                    -ComputerName $compname
        $PCNetAdpts | Where-Object {$_.Description.Substring(0,9) -ne 'Microsoft' -and `
                                    $_.DHCPEnabled -eq 'True'} | 
         Select-Object Description | Format-table $fmtPCNetAdpts
    }
          
    #PC Printer Information 
     $ptrfmt = @{Expression={ $_.DeviceID};Label="Printer";Width=36},
               @{Expression={$_.DriverName};Label="Driver";Width=25},
               @{Expression={$_.PortName};Label="Port";width=15}
    
                "Installed Printer Information:"
                get-WMIObject -computer $compname Win32_Printer | `
                Select-Object DeviceID,DriverName, PortName | `
                Sort-Object DeviceId | Format-Table $ptrfmt
    
    #Selected Registry Key Information
    
    "Selected Windows Settings:"
    
      $CITable = $null   #Clear Table
    # Re-Create Table
      $CITable = New-Object system.Data.DataTable "Registry Information"
    #Create Columns for table 
      $CITcol1 = New-Object system.Data.DataColumn Item,([string])       
      $CITcol2 = New-Object system.Data.DataColumn Value,([string])
    #Add Columns to table
      $CITable.columns.add($CITcol1)
      $CITable.columns.add($CITcol2)
    
     Get-ItemProperty `
          -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power' `
          -Name HiberbootEnabled   | `
          Add-Row -ItemName "Registry: HiberbootEnabled" `
                  -ItemValue $($_.HiberbootEnabled -eq 1)
    
     Get-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Power" `
                      -Name HibernateEnabled | `
          Add-Row -ItemName "Registry: HibernateEnabled" `
                  -ItemValue $($_.HibernateEnabled -eq 1)
    
    
     Get-Service -Name HomeGroup* | `
           ForEach-Object  {
          Add-Row -ItemName "Service:  $($_.DisplayName)" -ItemValue $($_.Status)
        }
    
    #Output table -- Selected Windows Settings:
    
      $fmt = @{Expression={$_.Item};Label="Item";width=40},
             @{Expression={$_.Value};Label="Value";Width=20}
    
     $CITable | Select-Object Item,Value | Format-Table $fmt
    
    #Non-Windows Unique Drivers and Version Numbers
    
    "Non-Windows Unique Drivers and Version Numbers"
    
      $fmt = @{Expression={$_.DeviceName};Label="Driver Description";width=40},
             @{Expression={$_.DriverVersion};Label="Version Number";Width=30}
    
      Get-WmiObject Win32_PNPSignedDriver | `
         Where DriverVersion -notlike "6.3.9600.*" | `
         Sort-Object -Property DriverVersion -Unique | `
         Format-Table $fmt
                   
    #Installed Programs Info
    
    "Installed Programs:"
    
    
    $fmt = @{Expression={$_.DisplayName};Label="Program Name";width=30},
           @{Expression={$_.InstallDate};Label="Installed";width=9},
           @{Expression={$_.InstallLocation};Label="Install Path";width=41}
    
    if (!([Diagnostics.Process]::GetCurrentProcess().Path -match '\\syswow64\\'))
    {
      $unistallPath = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
      $unistallWow6432Path = `
        "\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
      @(
        if (Test-Path "HKLM:$unistallWow6432Path" ) { 
          Get-ChildItem "HKLM:$unistallWow6432Path"}
        if (Test-Path "HKLM:$unistallPath" ) { 
          Get-ChildItem "HKLM:$unistallPath" }
        if (Test-Path "HKCU:$unistallWow6432Path") { 
          Get-ChildItem "HKCU:$unistallWow6432Path"}
        if (Test-Path "HKCU:$unistallPath" ) { 
          Get-ChildItem "HKCU:$unistallPath" }
       ) |
       Where-Object {
         $_.GetValue('DisplayName') -and `
        ($_.GetValue('UninstallString') -or `
         $_.GetValue('NoRemove')) -and `
        !$_.GetValue('SystemComponent') -and `
        !$_.GetValue('ReleaseType') -and `
        !$_.GetValue('ParentKeyName')
      } |
      Get-ItemProperty |  Sort-Object DisplayName |
      Select-Object DisplayName,InstallDate,InstallLocation | 
      Format-Table $fmt
    }
    else
    {
      Write-Host `
        "You are running 32-bit Powershell on 64-bit system.`n" `
        'Please run 64-bit Powershell instead.'  -ForegroundColor Red
    }
    Last edited by RetiredGeek; 2015-01-16 at 18:19.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  12. #11
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,726
    Thanks
    147
    Thanked 156 Times in 149 Posts
    Very good! Does this remove the need for Belarc?

    BTW one major coding problem - privledges is spelt privileges

  13. #12
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Access,

    Thanks for the catch! Fixed in above post. I wish all my coding problems were so MAJOR!

    As to replacing Belarc I don't think I have all the stuff they report but then I report some stuff they don't and my code can easily generate a Text file for what ever use you want via a output redirection on the command line. Of course this is a work in progress so who knows in the future maybe?
    Last edited by RetiredGeek; 2015-01-16 at 18:24.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  14. #13
    Silver Lounger wavy's Avatar
    Join Date
    Dec 2009
    Location
    ny
    Posts
    2,378
    Thanks
    235
    Thanked 147 Times in 136 Posts
    RG
    Very nice .

    eeerrr umm whats it do ??
    I am on Mint at the moment

    And I really gotta change my kill program short cut to something other than ^x before I loose something important...
    David

    Just because you don't know where you are going doesn't mean any road will get you there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •