Sample PowerShell code for getting the Chrome extensions and putting in WMI for collection with PDQ inventory. This worked in my testing on systems with suspicious web connections to determine what extensions were installed that might be causing the problem. Using the Preferences file seems more reliable than looking in the manifest.json files, reg keys or internet. As with any environment your mileage may vary.

# PS script to get Chrome Ext and put in WMI
# Some code from Ivanti, rewritten to not browse extension folders or go to web for extension names. Added extra fields. 
# Original idea I saw was from SKissinger for SCCM 2012. Saw Preference file reference in SpiceWorks post for Chrome on unix.

# Now uses Chrome Preferences file.


# Need to run with admin permissions to manipulate WMI.


function Convert-UTCtoLocal {
param(
[parameter(Mandatory=$true)]
[String] $UTCTime
)

    $strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
    $TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
    $LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
    return $LocalTime
}



#setup or clear WMI class
if(Get-WmiObject -List | where { $_.Name -eq "pdqChromeExtension"}){

    #Clear existing WMI entries to re-enumerate extensions
    #Get-WmiObject pdqChromeExtension | Remove-WmiObject
    Remove-CimInstance -Query 'select * from pdqChromeExtension'
}
else{
        $newClass = New-Object System.Management.ManagementClass ("root\cimv2", [String]::Empty, $null); 

        $newClass["__CLASS"] = "pdqChromeExtension"; 

        $newClass.Qualifiers.Add("Static", $true)

        $newClass.Properties.Add("Name", [System.Management.CimType]::String, $false)
        $newClass.Properties["Name"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("Version", [System.Management.CimType]::String, $false)
        $newClass.Properties["Version"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("EnableState", [System.Management.CimType]::String, $false)
        $newClass.Properties["EnableState"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("Description", [System.Management.CimType]::String, $false)
        $newClass.Properties["Description"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("Permissions", [System.Management.CimType]::String, $false)
        $newClass.Properties["Permissions"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("ID", [System.Management.CimType]::String, $false)
        $newClass.Properties["ID"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("DateInstall", [System.Management.CimType]::String, $false)
        $newClass.Properties["DateInstall"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("DefaultInstall", [System.Management.CimType]::String, $false)
        $newClass.Properties["DefaultInstall"].Qualifiers.Add("Key", $true)

        $newClass.Properties.Add("OemInstall", [System.Management.CimType]::String, $false)
        $newClass.Properties["OemInstall"].Qualifiers.Add("Key", $true)



        $newClass.Properties.Add("User", [System.Management.CimType]::String, $false)
        $newClass.Properties["User"].Qualifiers.Add("Key", $true)
        
        $newClass.Properties.Add("ChromeVer", [System.Management.CimType]::String, $false)
        $newClass.Properties["ChromeVer"].Qualifiers.Add("Key", $true)
        
        $newClass.Properties.Add("LastScan", [System.Management.CimType]::String, $false)
        $newClass.Properties["LastScan"].Qualifiers.Add("Key", $true)
        
        $newClass.Put()
} # end if else


$parentdir = "C:\Users\"
$users = Get-ChildItem $parentdir
$ObjCollection = @()

Foreach($user in $users){

    # get profile folder
    $targetdir = ""
    $chromedir = $parentdir + $user.ToString() + "\AppData\Local\Google\Chrome\User Data"
    if (test-path "$chromedir\default") {$targetdir = "$chromedir\Default"}
    if (test-path "$chromedir\profile 1") {$targetdir = "$chromedir\Profile 1"}

    # read preferences file in Default folder
    if (test-path "$targetdir\Preferences") {
       $prefs = Get-Content "$targetdir\Preferences"  | ConvertFrom-Json  # Read Prefernces JSON file
    
       #get extension names  
       $extensions = $prefs.extensions.settings | gm -type NoteProperty| ForEach-Object {$_.name}
 
       Foreach($ext in $extensions){
 
            $obj = New-Object System.Object
            $pref = $($prefs.extensions.settings.$($ext))
            $Permissions = ""  # force permissions variable to string

            # view variable contents for testing
            # $pref 
            # $pref.manifest

            $name = $pref.manifest.name
            $state = $pref.state
            $version = $pref.manifest.version
            $description = $pref.manifest.description
            $DefaultInstall = $pref.was_installed_by_default
            $OemInstall = $pref.was_installed_by_oem
            $Ptemp = $pref.manifest.permissions
            foreach ($pt in $Ptemp) {$Permissions = $Permissions + $pt.tostring() + "._."} # convert array to string to store in WMI. Use ._. entry separator.
            $ChromeVer = $prefs.extensions.last_chrome_version

            # install time conversion
            $p = [double]$pref.install_time
            $p = ($p - 11644473600000000 ) / 1000000 #//divide by 1,000,000 because we are going to add seconds on to the base date
            $date = get-date -date "1970-01-01 00:00:00"
            $date = $date.AddSeconds($p)
            $localtimezn = Convert-UTCtoLocal($date)


            #get name and version from json and add to object
            $obj | Add-Member -MemberType NoteProperty -Name Name -Value $name
            $obj | Add-Member -MemberType NoteProperty -Name Version -Value $version
            $obj | Add-Member -MemberType NoteProperty -Name EnableState -Value $state
            $obj | Add-Member -MemberType NoteProperty -Name Description -Value $description
            $obj | Add-Member -MemberType NoteProperty -Name DefaultInstall -Value $DefaultInstall
            $obj | Add-Member -MemberType NoteProperty -Name OemInstall -Value $OemInstall
            $obj | Add-Member -MemberType NoteProperty -Name Permissions -Value $Permissions
            $obj | Add-Member -MemberType NoteProperty -Name ID -Value $ext.ToString()
            $obj | Add-Member -MemberType NoteProperty -Name DateInstall -Value $localtimezn.ToString()

            $obj | Add-Member -MemberType NoteProperty -Name User -Value $user
            $obj | Add-Member -MemberType NoteProperty -Name ChromeVer -Value $ChromeVer
            $obj | Add-Member -MemberType NoteProperty -Name LastScan -Value $(Get-Date)


            # ignore blank names 
            if($name -ne $null){            
                Set-WmiInstance -Class pdqChromeExtension -Puttype CreateOnly -Argument @{Name = $obj.Name; Version = $obj.Version; EnableState = $obj.EnableState; Description = $obj.Description; DefaultInstall = $obj.DefaultInstall; OemInstall = $obj.OemInstall; Permissions = $obj.Permissions; ID = $obj.ID; DateInstall = $obj.DateInstall; User = $obj.User; ChromeVer = $obj.ChromeVer; LastScan = $obj.LastScan} -ErrorAction SilentlyContinue
            

                # items for testing or debug. Not saved in WMI class
                #$obj

                $ObjCollection += $obj  # used for examining the data later for troubleshooting. 
            }
        
       } # end foreach extensions
    } # end if pref file found
} # end foreach users
Cancel
login to comment