如何监控 Microsoft Outlook 以确定加载时间和涉及使用第三方程序、PowerShell 或 C# 的因素?

How do I monitor Microsoft Outlook to determine load time and factors involved using a third party program, PowerShell, or C#?

我的任务是查找或创建第三方应用程序,该应用程序将用于自动化以监控打开 Microsoft Outlook 所需的时间并记录打开时采取的所有操作,例如插件, .ost 或 .pst 文件大小,open/shared 个共享邮箱。我在网上搜索了可以执行此操作的第三方应用程序或 PowerShell 程序。我什至搜索了关于如何开发 PowerShell 脚本的起点,甚至开始用 C# 编写可以执行此操作的程序。我正在使用 Microsoft Outlook 2016。我目前处于 C# 编程的中级水平,并且正在学习更多以完成此项目。我有以下问题:

  1. 有谁知道可以实现此目标的第 3 方或 PowerShell 脚本吗?

  2. 或者,我什至如何开始 C# 脚本来完成此操作?

感谢您的帮助。

我不能完全回答你的问题,但我可能对如何监控outlook的启动速度有所了解。使用 powershell 或 C#,您可以启动 Outlook 并测量完全启动它所花费的时间。也许可以使用 Outlook COM 接口收集更多信息,但这样您至少可以看到时间安排。

显示启动速度的简单测试脚本 (Powershell):

Add-Type -assembly "Microsoft.Office.Interop.Outlook"

$sw = [Diagnostics.Stopwatch]::StartNew()

$Outlook = New-Object -comobject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
$folder = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$explorer = $folder.GetExplorer()
$explorer.Display()

$sw.Stop()
$sw.Elapsed

所以在让经验丰富的程序员看过我的脚本后,他做了一些必要的修改和评论。

clear-host
$CSVFile = Read-Host "Enter CSV log file and path - (C:\temp\outlook.csv)"
$ProcMonTest = Read-Host "Enter app path - (C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE)"
$ProcMon = "C:\tools\Procmon.exe" # this would be the path to wherever procmon.exe is
$ProcMonBack = "C:\Temp\ProcMonTest.pml"
$LaunchBAT = Read-Host "Enter path to the BAT file to launch the app to be tested - (c:\tools\StartOutlook.bat)" # use a bat file to get past PowerShell security
$CredsForApp = $host.ui.PromptForCredential("Run App As?", "Enter creds in domain\username format to run testing app:", "", "") # this gives us the creds to run the app to be tested as 
 
# make sure backing file isn't present in case it wasn't deleted on last run
$FileExists = Test-Path $ProcMonBack
if ($FileExists -eq $true){
Remove-Item $ProcMonBack -force
}
 
& $ProcMon /Quiet /AcceptEula /Minimized /backingfile $ProcMonBack 
 
do{
Start-Sleep -seconds 90 # procmon.exe /waitforidle doesn't appear to work well when scripted with PowerShell
$ProcMonProcess = Get-Process | where {$_.Path -eq $ProcMon}
}while(
$ProcMonProcess.Id -eq $null
)
(Start-Process cmd -Credential $CredsForApp -Argument "/c $LaunchBAT")

Start-Sleep -seconds 90 # adjust this time based on how long the test run is needed
 
$ProcMonTestProcess = Get-Process | where {$_.Path -eq $ProcMonTest}
Stop-Process $ProcMonTestProcess.Id -Force
 
& $ProcMon /Terminate
 
Start-Sleep -seconds 60 # procmon.exe can take a long time to exit, this ensures it does before proceeding
 
# Read the procmon.exe backing file and export as CSV
& $ProcMon /openlog $ProcMonBack /SaveAs $CSVFile
& $ProcMon /Terminate

Start-Sleep -seconds 60 # procmon.exe can take a long time to exit, this ensures it does before proceeding

# Clean up procmon.exe backing file
$FileExists = Test-Path $ProcMonBack
if ($FileExists -eq $true){
Remove-Item $ProcMonBack -force
}