1
\$\begingroup\$

There are some Kiosk machines for people to take a survey. The survey is running by a 3rd party, so no way to get the data from them. To measure how much machines are in use I wrote a script to pull Edge-Chromium browsing history from a remote machine

function Copy-FileRemotely
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true,
                   Position = 0)]
        [string]$ComputerName
    )
    
    try
    {       
        $isSuccess = $true
        $Message = Copy-Item -Path "\\$ComputerName\c$\Users\SMZSurvey2\AppData\Local\Microsoft\Edge\User Data\Default\History" -Destination $PSScriptRoot\$ComputerName -Force -ErrorAction Stop -PassThru
    }
    catch
    {
        $isSuccess = $false
        $Message = ($_.Exception).Message
    }
    return [pscustomobject]@{
        'ComputerName'   = $ComputerName
        'isSuccess'      = $isSuccess
        'Message'        = $Message
        
    }
    
}

$comps = "smz-F9246-DB", "xxx"
$result = @()
foreach ($comp in $comps)
{
    $result += Copy-FileRemotely $comp
}
$result | Out-GridView
sleep 10
```
\$\endgroup\$
5
  • \$\begingroup\$ just for my curiosity ... how does the cache give you "how much machines are in use"? \$\endgroup\$
    – Lee_Dailey
    Commented Jun 5, 2021 at 20:38
  • \$\begingroup\$ @Lee_Dailey The history file contains titles of pages a user visited, the datestamps, etc. When a person finishes a survey, Edge displays him the "Thank you!" page. I guess I count those pages per day. It gives me the number of people that took a survey test on a particular machine. \$\endgroup\$ Commented Jun 5, 2021 at 20:55
  • \$\begingroup\$ ah! thank you for the "why" of it. [grin] ///// i would likely use Invoke-Command to run your code on each system in parallel and let the count be sent back to you instead of the whole list of pages. i suspect that could get QUITE large ... and make things rather slow when sent across the network. \$\endgroup\$
    – Lee_Dailey
    Commented Jun 5, 2021 at 22:52
  • \$\begingroup\$ @Lee_Dailey Edge-Chromium keeps its browsing history data in SQLite database which stored in a file called History. I don't know how to decipher the file with Invoke-Command. \$\endgroup\$ Commented Jun 6, 2021 at 11:41
  • \$\begingroup\$ ah! i presumed you had code that you were running to decipher that info. if you DO have something that you can run on the target systems, then i would do that. less to shove across your network AND running the code in parallel makes it seem worth your while. \$\endgroup\$
    – Lee_Dailey
    Commented Jun 6, 2021 at 20:26

1 Answer 1

2
\$\begingroup\$

To make what you have more readable, I would not create a helper function to replace Copy-Item:

$comps = "smz-F9246-DB", "xxx"

$result = foreach ($comp in $comps) {
  Try { Copy-Item `
    -Path "\\$comp\c$\Users\SMZSurvey2\AppData\Local\Microsoft\Edge\User Data\Default\History" `
    -Destination "$PSScriptRoot\$ComputerName" -Force -PassThru
  }
  Catch [Common.Exceptions.You.See] { Write-Output "$comp could not be contacted, skipping..." }
}

# output list of files/failures
$result

Based on your comments, you just want the count of visits to a specific site, which is pretty straightforward if you have powershell remoting available. I adapted this code by user rvrsh3ll, which pulls website names from the chromium History file.

# Connect to each machine and get the browsing history
$result = Foreach ($comp in $comps) {

  Try { 
  Invoke-Command -ComputerName $comp -EA Stop -ScriptBlock {

    # Regex returns trimmed URL
    $Regex = '(http(|s))://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?'
    $Site = 'https://stackoverflow.com'  # Set this

    # Seach chrome history for site visits
    $Count = (
      Get-Content -Path "C:\Users\SMZSurvey2\AppData\Local\Microsoft\Edge\User Data\Default\History" -EA Stop|
      Select-String -AllMatches $regex |
      % {($_.Matches).Value} | 
      Where {$_ -like $Site}
    ).Count

    # output as object
    [PSCustomObject]@{
      ComputerName = $using:comp
      SiteVisits   = $Count
      Success      = ($Count -gt -1) -and ($null -ne $Count)
    }
  } 
  } Catch {[PSCustomObject]@{ComputerName=$comp;SiteVisits='N/A';Success=$false}}
}

# Output results:
$result | FT ComputerName,SiteVisits,Success

And the results look like so:

ComputerName SiteVisits Success
------------ ---------- -------
offline-PC   N/A          False
in-use-PC    2             True
unused-PC    0             True

Hopefully this helps you skip the step of processing the file.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.