显示前景约会的持续时间?

时间:2019-05-06 11:37:08

标签: powershell outlook scripting

我无法在列表框中显示每个约会的持续时间。我正在尝试在列表框11:30中打印; (60)B / H或11:30-12:30; B / H,但是不确定如何执行此操作,请有人帮忙吗?

我尝试过$Duration$._Duration,将它们放在"[...]Start.ToString('HH:mm'), $_.Subject } " 'HH:mm'$_. subject之间,但是这些方法都没有成功

#listbox for calendar entry
$Listboxcal= New-Object System.Windows.Forms.ListBox 
$Listboxcal.Location = New-Object System.Drawing.Size(10,55) 
$Listboxcal.Size = New-Object System.Drawing.Size(80,270) 
$Listboxcal.Height = 150

add-type -assembly “Microsoft.Office.Interop.Outlook” | out-null
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace(“MAPI”)
# https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook.oldefaultfolders?view=outlook-pia
# Calendar = olFolderCalendar = 9
$calendar = $namespace.GetDefaultFolder(9)
# get today's calendar items!
 $cItems = $calendar.Items | Where-Object {$_.Start -ge $(Get-Date $StrCaldate) -and $_.Start -le $(Get-Date $StrCaldate).AddDays(1)} |Sort-Object -Property Start | foreach { "{0}; {1}" -f $_.Start.ToString('HH:mm'), $_.Subject } 
ForEach ($calendars in $cItems) {[void]$Listboxcal.Items.Add($calendars)}

2 个答案:

答案 0 :(得分:1)

日历约会具有duration属性。您只需要将其添加到$cItems变量

$cItems = $calendar.Items | Where-Object {$_.Start -ge $(Get-Date $StrCaldate) -and $_.Start -le $(Get-Date $StrCaldate).AddDays(1)} |Sort-Object -Property Start | foreach { "{0}; ({1}) {2}" -f $_.Start.ToString('HH:mm'), $_.Duration, $_.Subject }

当我在自己的日历上运行它时,我得到以下信息:

16:30; (60) Appointment 1 18:30; (120) Appointment 2

答案 1 :(得分:0)

它对我来说具有Duration属性:

$calendar.Items | Select -First 1 | %{ $_.StartUTC.Tostring("hh:mm") `
+ "; (" + $_.Duration + ") " + $_.Subject}