我在使用下面的代码时遇到了一些问题。我试图弄清楚如何让输出适用于所有用户配置文件,而不仅仅是当前用户。如果我使用 $shell.NameSpace(34) 代码有效(两行注释掉)。但是当我尝试覆盖 shell.namespace 并手动添加路径时,我收到一个错误,即方法项不存在。想知道解决或解决此问题的最佳方法是什么。
实际错误消息:方法调用失败,因为 [System.String] 不包含名为“Items”的方法。
感谢您的帮助。
$shell = New-Object -ComObject Shell.Application
$colProfiles = Get-ChildItem "C:\Users\" -Name
#$hist = $shell.NameSpace(34)
#Write-Host $hist
foreach ( $userProfile in $colProfiles )
{
[string]$hist = "C:\Users\$userProfile\AppData\Local\Microsoft\Windows\History"
$date = ""
$url = ""
$hist.Items() | foreach {
""; "";
if ($_.IsFolder)
{
$siteFolder = $_.GetFolder
$siteFolder.Items() | foreach {
$site = $_
"";
if ($site.IsFolder)
{
$pageFolder = $site.GetFolder
Write-Host $pageFolder
$pageFolder.Items() | foreach {
$url = $pageFolder.GetDetailsOf($_,0)
$date = $pageFolder.GetDetailsOf($_,2)
echo "$date $url"
}
}
}
}
}
}