Categories

IE History

Saw a post on the forums that looked interesting.

Problem

Convert  this VBScript into PowerShell

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
HISTORY_LIST = 34
ITEM_NAME = 0
ITEM_DATE = 2
Set objShell = CreateObject("Shell.Application")
Set objHistory = objShell.NameSpace(HISTORY_LIST)
Set objHistoryFolder = objHistory.Self
Wscript.Echo vbCrLf & "Location of History"
Wscript.Echo objHistoryFolder.Path


For Each objPeriod In objHistory.Items

  Wscript.Echo vbCrLf & objPeriod.Name
  Wscript.Echo String(Len(objPeriod.Name), "=")

 If objPeriod.IsFolder Then
    Set objSiteFolder = objPeriod.GetFolder


    For Each objSite In objSiteFolder.Items
      Wscript.Echo vbCrLf & objSite.Name
      Wscript.Echo String(Len(objSite.Name), "-")

      If objSite.IsFolder Then
        Set objPageFolder = objSite.GetFolder

        For Each objPage In objPageFolder.Items
          strURL = objPageFolder.GetDetailsOf(objPage,ITEM_NAME)
          WScript.Echo vbCrLf & "URL: " & strURL
          strDateVisited = objPageFolder.GetDetailsOf(objPage,ITEM_DATE)
          WScript.Echo "Date Visited: " & strDateVisited
        Next

      End If

   Next

  End If
Next

 

The script came from http://gallery.technet.microsoft.com/ScriptCenter/en-us/28696fd5-2a90-4766-9b96-d4bc38c9db12 and interestingly was only stated to work on Windows 2000 and Windows XP

For my first go I did a straight conversion

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
$shell = New-Object -ComObject Shell.Application
$hist = $shell.NameSpace(34)
$folder = $hist.Self
$folder.Path

$periods = $hist.Items()
foreach ($period in $periods){
    ""
    ""
    $period.Name
   
    if ($period.IsFolder) {
        $siteFolder = $period.GetFolder
        $sites = $siteFolder.Items()
       
        foreach ($site in $sites) {
            ""
            $site.Name
           
            if ($site.IsFolder) {
                $pageFolder  = $site.GetFolder
                $pages = $pageFolder.Items()
               
                foreach ($page in $pages) {
                    $url = $pageFolder.GetDetailsOf($page,0)
                    $date =  $pageFolder.GetDetailsOf($page,2)
                    "$date visited $url" 
                }
            }
        }
    } 
}

 

We start off the same in creating a COM object and access special folder 34 – the IE history.

After displaying the folder path we get the periods and iterate through them, displaying the name – this will be the day of the week or Last week etc

We check if the period is a folder and if it is we get the items in the folder.

We can then iterate through them displaying the site name and checking if it is a folder.

if it is we can get the pages visited and display the URL and the date visited.

While this worked I was 100% happy with it because of the nested foreachs.  I wanted to do more on the pipeline so I had another go

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
$shell = New-Object -ComObject Shell.Application
$hist = $shell.NameSpace(34)
$folder = $hist.Self
$folder.Path

$hist.Items() | foreach {
    ""; ""; $_.Name
     if ($_.IsFolder) {
         $siteFolder = $_.GetFolder
         $siteFolder.Items() | foreach {
            $site = $_
            ""; $site.Name
            if ($site.IsFolder) {
                $pageFolder  = $site.GetFolder
                $pageFolder.Items() | foreach {
                    $url = $pageFolder.GetDetailsOf($_,0)
                    $date =  $pageFolder.GetDetailsOf($_,2)
                    "$date visited $url" 
                }
            }
         }
     }
}

 

This does exactly the same as the first attempt. It could be made more compact but is already getting a bit hard to understand. For once the more verbose way may be better.

BTW I did this on Windows 7

3 Responses to IE History

  • Justin says:

    Is is possible to use this same method on a remote machine?

  • RichardSiddaway says:

    It wouldn’t be easy to do this directly as the IE history is specific to the user account. It would be possible to user PowerShell remoting to access the info if you had PowerShell v2 on both machines

  • Robert Flynn says:

    Is there a way that this script can be modified to list the IE history of all users on a windows 7 machine? I tried using that IEspy.vbs script but it only runs on Windows XP.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>