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 If objPeriod.IsFolder Then For Each objSite In objSiteFolder.Items If objSite.IsFolder Then For Each objPage In objPageFolder.Items End If Next End If |
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() |
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 { |
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
By: Justin on April 20, 2010 at 8:57 pm
Is is possible to use this same method on a remote machine?
By: RichardSiddaway on April 21, 2010 at 1:16 pm
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
By: Robert Flynn on November 2, 2012 at 10:30 am
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.