Prathamesh Wagh
Prathamesh Wagh

Reputation: 55

Powershell script to create a meeting in outlook

I am trying to create a PowerShell script to create a meeting in the Outlook. I am stuck in the code for setting up the timezone of the meeting. The time zones I am looking for is CST, PST, EST, AEST.

$Outlook = New-Object -ComObject Outlook.Application
$OutlookFolders = $Outlook.Session.Folders.Item(1).Folders
$tzs = $Outlook.TimeZones
$NewEvent = $Outlook.CreateItem(1)
$NewEvent.Subject = "Meeting";
$NewEvent.Start = [datetime]”6/13/2019 19:00"
$NewEvent.End = [datetime]"6/13/2019 20:00"
$NewEvent.StartTimeZone =$tzs.CurrentTimeZone.Name("Central Standard 
Time")
$NewEvent.EndTimeZone = $tzs.CurrentTimeZone.Name("Central Standard 
Time")
$NewEvent.SendUsingAccount = '[email protected]'
$NewEvent.Recipients('[email protected]')
$NewEvent.save()

Error I am getting for above code is listed below

Cannot find an overload for "ID" and the argument count: "1" At C:\Powershell\outlook-base.ps1:12 char:5 + $NewEvent.StartTimeZone = $Outlook.TimeZones.CurrentTimeZone.ID(" ... + CategoryInfo : NotSpecified: (:) [], GetValueInvocationException + FullyQualifiedErrorId : RuntimeException Cannot find an overload for "ID" and the argument count: "1" At C:\Powershell\outlook-base.ps1:13 char:5 + $NewEvent.EndTimeZone = $Outlook.TimeZones.CurrentTimeZone.ID("Ce ... + CategoryInfo : NotSpecified: (:) [], GetValueInvocationException + FullyQualifiedErrorId : RuntimeException

Upvotes: 2

Views: 2041

Answers (1)

Axel Andersen
Axel Andersen

Reputation: 1128

Update line 8 and 9 with this:

$NewEvent.StartTimeZone =$tzs["Central Standard Time"]
$NewEvent.EndTimeZone = $tzs["Central Standard Time"]

Upvotes: 3

Related Questions