IE history to CSV

Back in April last year I wrote a post about viewing IE history

http://msmvps.com/blogs/richardsiddaway/archive/2010/04/13/ie-history.aspx

I had a comment left asking how this could be put into a CSV file

We’ll start by turning the script into an advanced function that outputs an object

function get-iehistory {            
[CmdletBinding()]            
param ()            
            
$shell = New-Object -ComObject Shell.Application            
$hist = $shell.NameSpace(34)            
$folder = $hist.Self            
            
$hist.Items() |             
foreach {            
 if ($_.IsFolder) {            
   $siteFolder = $_.GetFolder            
   $siteFolder.Items() |             
   foreach {            
     $site = $_            
             
     if ($site.IsFolder) {            
        $pageFolder  = $site.GetFolder            
        $pageFolder.Items() |             
        foreach {            
           $visit = New-Object -TypeName PSObject -Property @{            
               Site = $($site.Name)            
               URL = $($pageFolder.GetDetailsOf($_,0))            
               Date = $( $pageFolder.GetDetailsOf($_,2))            
           }            
           $visit            
        }            
     }            
   }            
 }            
}            
}

The main changes are to stop writing strings to the output and to create an object to put the data into.

Run the function by dot sourcing the file you have the script in – its easier to do this in ISE Then try these commands

get-iehistory
get-iehistory | export-csv iehistory.csv -TypeInformation
Import-Csv iehistory.csv

Published Wed, Jun 29 2011 21:12 by RichardSiddaway
Filed under: , ,

Comments

# re: IE history to CSV

- function get-iehistory

add "Title" to foreach { $visit  ... }:

Title = $( $pageFolder.GetDetailsOf($_,1))

I wrote "Graphics interpretation" of data taken by your script

- run PS>get-iehistory.ps1 | export-csv -Path 'C:\ieh.csv' -NoTypeInformation -Delimiter ";" -Encoding 'UTF8'

- run PS>get-iehistory-Graph.ps1

get-iehistory-Graph.ps1

Clear-Host

# Load Assembly

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization") | Out-Null

# Create ChartArea

$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea

$ChartArea.Area3DStyle.Enable3D = $false

# X

$ChartArea.AxisX.Title = "X - URL" # jmeno osy

$ChartArea.AxisX.Interval = 1 # jak casto je cara

$ChartArea.AxisX.IntervalOffset = 0 # posun cislovani osy

$ChartArea.AxisX.LabelStyle.Interval = 1 # jak casto je popis

#$ChartArea.AxisY.LabelStyle.Format = '' # viz $Chart.Series["Data"].XValueType

$ChartArea.AxisY.LabelStyle.IsEndLabelVisible = $true # vypisovat prvni-posledni

# Y

$ChartArea.AxisY.Title = "Y - čas" # jmeno osy

$ChartArea.AxisY.Interval = 1 # jak casto je cara

$ChartArea.AxisY.IntervalOffset = 0 # posun cislovani osy

$ChartArea.AxisY.LabelStyle.Interval = 1 # jak casto je popis

$ChartArea.AxisY.LabelStyle.Format = 'yyyy-MM-dd HH:m' # format datumu, viz $Chart.Series["Data"].YValueType

$ChartArea.AxisY.LabelStyle.IsEndLabelVisible = $true # vypisovat prvni-posledni

# zoom, scroll

$ChartArea.CursorX.IsUserEnabled = $true

$ChartArea.CursorX.IsUserSelectionEnabled = $true

$ChartArea.CursorY.IsUserEnabled = $true

$ChartArea.CursorY.IsUserSelectionEnabled = $true

# object Graphic

$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart

$Chart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left

# $Chart.Width = 500

# $Chart.Height = 500

$Chart.Left = 0

$Chart.Top = 0

$Chart.ChartAreas.Add($ChartArea)

$Chart.chartAreas[0].AxisX.LabelStyle.Font = new-object system.drawing.font("Courier New",10,[system.drawing.fontstyle]::Regular)

$Chart.chartAreas[0].AxisY.LabelStyle.Angle = 90

# Change the color of the text box

# BackColor: A choice of colors

$Chart.BackColor = [System.Drawing.Color]::White

# Palette: None,Bright,Grayscale,Excel,Light,Pastel,EarthTones,SemiTransparent,Berry,Chocolate,Fire,SeaGreen,BrightPastel

$Chart.Palette = [System.Windows.Forms.DataVisualization.Charting.ChartColorPalette]::Excel

# Adding Title and Labels

[void]$Chart.Titles.Add("Graf")

$Chart.Titles[0].Font = 'Arial,10pt'

$Chart.Titles[0].Alignment = 'topCenter'

# Adding Data in Chart

[void]$Chart.Series.Add("Data")

# The data Chart

$Chart.Series["Data"].Sort([System.Windows.Forms.DataVisualization.Charting.PointSortOrder]::Ascending, "Y")

# Applicable chart elements: Series, DataPoint

# Value range: Cylinder, Emboss, LightToDark, Wedge, Default

$Chart.Series["Data"]["DrawingStyle"] = "Default"

# Series.ChartType: Point, FastPoint, Bubble, Line, Spline, StepLine, FastLine, Bar, StackedBar, StackedBar100, Column, StackedColumn,

# StackedColumn100,Area, SplineArea, StackedArea, StackedArea100, Pie, Doughnut, Stock, Candlestick, Range, SplineRange,

# RangeBar, RangeColumn, Radar,Polar, ErrorBar, BoxPlot, Renko, ThreeLineBreak, Kagi, PointAndFigure, Funnel, Pyramid

$Chart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::RangeBar

# Chart ValueType - LabelStyle.Format

$Chart.Series["Data"].XValueType = [System.Windows.Forms.DataVisualization.Charting.ChartValueType]::String

$Chart.Series["Data"].YValueType = [System.Windows.Forms.DataVisualization.Charting.ChartValueType]::DateTime

# nacteni dat

# cesta k LogStatus-Debug.csv nebo Log_LogStatusDebug-SaveToLocal.csv

$logPath = 'C:\Users\user\SkyDrive\Vasek\IE\ieh.csv'

# CSV file DateTime format

$Culture = [System.Globalization.CultureInfo]::GetCultureInfo("en-us")

$FormatString = 'dd.MM.yyyy HH:mm'

# find the oldest and the newest record

$log = Import-Csv -Delimiter ';' -Path $logPath | Sort-Object @{expression={$_.Date -as [DateTime]}}

$index = 0

$Value = $log[$index].Date

$Value

[DateTime]$LogStop = [System.DateTime]::ParseExact($Value,$FormatString,$Culture)

$Value = $log[$log.Count-1].Date

[DateTime]$LogStart = [System.DateTime]::ParseExact($Value,$FormatString,$Culture)

[DateTime]$LogStop

[DateTime]$LogStart

# sort graph by URL

$log = Import-Csv -Delimiter ';' -Path $logPath | Sort-Object -Property 'Site'

# sort graph by DATE

# $log = Import-Csv -Delimiter ';' -Path $logPath | Sort-Object @{expression={$_.Date -as [DateTime]}}

[hashtable]$StartStop = @{}

[hashtable]$label = @{}

[hashtable]$legend = @{}

[int]$labelId = 0

[int]$TotalTime = 0

foreach ($line in $log) {

# "Date";"Title";"Site";"URL"

# $line.Date + ";" + $line.Index + ";" + $line.ScriptFile + ";" + $line.Type + ";" + $line.Period + ";" + $line.COMPUTERNAME

$Value = $line.Date

$startTime = [System.DateTime]::ParseExact($Value,$FormatString,$Culture)

$stopTime = $startTime.AddMinutes(1)

$TotalTime += 1

# if domain is not in label-list yet,  add to Label X

## $labelName = $($line.Site +' # '+ $line.Title).ToString()

$labelName = $($line.Site +' # ').ToString()

if ($label.ContainsKey($labelName)) {

# exist in Label-list, get Label ID

$labelId = $label.Get_Item($labelName)

} else {

# new Label, add Label ID and Name

$labelId = $label.Count +1

$label.Add($labelName, $labelId)

}

# draw point

[void]$Chart.Series["Data"].Points.AddXY($labelId, $startTime, $stopTime)

}

# transform [hashtable]$label to [hashtable]$legend ($label.$labelName=$labelId ==> $legend.Id=$labelName)

foreach ($labelKey in $label.Keys){

$legend.Add($label.get_Item($labelKey).ToString(), $labelKey)

}

# X axis legend

foreach ($bod in $Chart.Series["Data"].Points) {

# $bod.AxisLabel = $legend.Get_Item($($bod.XValue).ToString())

$temp = $legend.Get_Item($($bod.XValue).ToString())

$bod.AxisLabel = $temp -replace '#',$(' ' * (65-$temp.Split('#')[0].Length-$temp.Split('#')[1].Length))

}

# Displays the graph in the Windows Form

$Form = New-Object Windows.Forms.Form

$Form.Text = "PowerShell – Microsoft Chart Control"

# $Form.Width = $FormWidth

# $Form.Height = $FormHeight

$Form.WindowState = [System.Windows.Forms.FormWindowState]'Maximized'

$Form.Controls.Add($Chart)

$Form.Add_Shown({$Form.Activate()})

$Form.ShowDialog()

$($TotalTime / $(New-TimeSpan -Start $LogStop -End $LogStart).Days / 60)

Wednesday, April 17, 2013 5:34 AM by VasekB vaclav.berounsky@tiscali.cz

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: