其他用户的 IE 历史权限

IE History Permissions for other users

我有一个脚本,我认为它是能够为机器上的所有用户获取 IE 历史记录的大部分方法。我的问题是它对我以外的用户不起作用,因为我在尝试打开文件夹时遇到权限错误。有谁知道如何解决权限问题?

我 运行 在 Windows 2012r2 机器上运行这个脚本,我是这个盒子的管理员。

谢谢!

function Get-History 
{
    param
    (
        [string]$userName
    )

$shell = New-Object -ComObject Shell.Application 

if($username)
{
    $users = $username
}
else
{
    $users = Get-ChildItem C:\Users
}

if((([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")))
{
    Foreach($user in $users)
    {
        $user = Split-Path $user -leaf
        try
        {
            $ErrorActionPreference = 'Stop'
            $hist = $shell.NameSpace("C:\Users$user\AppData\Local\Microsoft\Windows\History") 
        }
        catch
        {
            continue
        }
        $folder = $hist.Self 
        #$folder.Path

            if($hist){
            $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) 
                                #"$user`: $date visited $url"  

                                #Write-Output ("$user,$date,`"$url`"" | ConvertFrom-Csv)

                                New-Object -TypeName PSObject -Property @{
                                                                          user=$user;
                                                                          date = $date;
                                                                          url = $url
                                                                          }
                            } 
                        } 
                     } 
                 } 
            }
        }    

    }
}
else
{
    Write-Host "Not Admin"
}
}

如果我 运行 只是一小段:

$shell = New-Object -ComObject Shell.Application            
$hist = $shell.NameSpace("C:\Users\MyOwnUsername\AppData\Local\Microsoft\Windows\History")

然后我成功地将 $hist 变量分配为 System.__ComObject

但是如果我运行:

$shell = New-Object -ComObject Shell.Application            
$hist = $shell.NameSpace("C:\Users\SomeOtherUser\AppData\Local\Microsoft\Windows\History")

我得到:

Exception calling "NameSpace" with "1" argument(s): "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
At line:3 char:1
+ $hist = $shell.NameSpace("C:\Users\SomeOtherUser\AppData\Local\Microsoft\Windows\History ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

完全披露:这是对 this blog post

处脚本的轻微修改

我一直没有解决权限问题。我更改了策略以使用 Nirsoft 的 BrowsingHistoryViewer。

$execPath = "C:\BrowsingHistoryView.exe"

$computers = 'computer1','computer2','computer3','computer4'

$outPath = "c:\"

$computers | 
    ForEach-Object{ `
        Start-Process $execPath `
            -argumentList "/HistorySource 3", 
                          "/HistorySourceFolder ""\$_\c$\Users""",
                          "/scomma ""$outpath\history_$_.txt"""
    }