Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add calendar event move #367

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 114 additions & 109 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,122 @@
* [PSGSuite - ChangeLog](#psgsuite---changelog)
* [2.36.5 - 2020-11-01](#2365---2020-11-01)
* [2.36.4 - 2020-03-20](#2364---2020-03-20)
* [2.36.3 - 2020-03-20](#2363---2020-03-20)
* [2.36.2 - 2020-03-02](#2362---2020-03-02)
* [2.36.1 - 2020-03-02](#2361---2020-03-02)
* [2.36.0 - 2020-02-28](#2360---2020-02-28)
* [2.35.1 - 2019-12-29](#2351---2019-12-29)
* [2.35.0 - 2019-12-29](#2350---2019-12-29)
* [2.34.0 - 2019-11-02](#2340---2019-11-02)
* [2.33.2 - 2019-10-06](#2332---2019-10-06)
* [2.33.1 - 2019-10-06](#2331---2019-10-06)
* [2.33.0 - 2019-09-26](#2330---2019-09-26)
* [2.32.3 - 2019-09-18](#2323---2019-09-18)
* [2.32.2 - 2019-09-15](#2322---2019-09-15)
* [2.32.1 - 2019-09-14](#2321---2019-09-14)
* [2.32.0 - 2019-09-12](#2320---2019-09-12)
* [2.31.1 - 2019-08-30](#2311---2019-08-30)
* [2.31.0](#2310)
* [2.30.2](#2302)
* [2.30.1](#2301)
* [2.30.0](#2300)
* [2.29.0](#2290)
* [2.28.2](#2282)
* [2.28.1](#2281)
* [2.28.0](#2280)
* [2.27.0](#2270)
* [2.26.4](#2264)
* [2.26.3](#2263)
* [2.26.2](#2262)
* [2.26.1](#2261)
* [2.26.0](#2260)
* [2.25.3](#2253)
* [2.25.2](#2252)
* [2.25.1](#2251)
* [2.25.0](#2250)
* [2.24.0](#2240)
* [2.23.2](#2232)
* [2.23.1](#2231)
* [2.23.0](#2230)
* [2.22.4](#2224)
* [2.22.3](#2223)
* [2.22.2](#2222)
* [2.22.1](#2221)
* [2.22.0](#2220)
* [2.21.3](#2213)
* [2.21.2](#2212)
* [2.21.1](#2211)
* [2.21.0](#2210)
* [2.20.2](#2202)
* [2.20.1](#2201)
* [2.20.0](#2200)
* [2.19.0](#2190)
* [2.18.1](#2181)
* [2.18.0](#2180)
* [2.17.2](#2172)
* [2.17.1](#2171)
* [2.17.0](#2170)
* [2.16.1](#2161)
* [2.16.0](#2160)
* [2.15.4](#2154)
* [2.15.3](#2153)
* [2.15.2](#2152)
* [2.15.1](#2151)
* [2.15.0](#2150)
* [2.14.1](#2141)
* [2.14.0](#2140)
* [2.13.2](#2132)
* [2.13.1](#2131)
* [2.13.0](#2130)
* [2.12.1](#2121)
* [2.12.0](#2120)
* [2.11.0](#2110)
* [2.10.2](#2102)
* [2.10.1](#2101)
* [2.10.0](#2100)
* [2.9.0](#290)
* [2.8.1](#281)
* [2.8.0](#280)
* [2.7.2](#272)
* [2.7.1](#271)
* [2.7.0](#270)
* [2.6.3](#263)
* [2.6.2](#262)
* [2.6.1](#261)
* [2.6.0](#260)
* [2.5.4](#254)
* [2.5.3](#253)
* [2.5.2](#252)
* [2.5.1](#251)
* [2.5.0](#250)
* [2.4.0](#240)
* [2.3.0](#230)
* [2.2.1](#221)
* [2.2.0](#220)
* [2.1.5](#215)
* [2.1.3 / 2.1.4](#213--214)
* [2.1.2](#212)
* [2.1.1](#211)
* [2.1.0](#210)
* [2.0.3](#203)
* [2.0.2](#202)
* [2.0.1](#201)
* [2.0.0](#200)
* [New Functionality](#new-functionality)
* [Breaking Changes in 2.0.0](#breaking-changes-in-200)
* [Gmail Delegation Management Removed](#gmail-delegation-management-removed)
* [Functions Removed](#functions-removed)
* [Functions Aliased](#functions-aliased)
- [PSGSuite - ChangeLog](#psgsuite---changelog)
- [2.37.0 - 2022-03-18](#2370---2022-03-18)
- [2.36.5 - 2020-11-01](#2365---2020-11-01)
- [2.36.4 - 2020-03-20](#2364---2020-03-20)
- [2.36.3 - 2020-03-20](#2363---2020-03-20)
- [2.36.2 - 2020-03-02](#2362---2020-03-02)
- [2.36.1 - 2020-03-02](#2361---2020-03-02)
- [2.36.0 - 2020-02-28](#2360---2020-02-28)
- [2.35.1 - 2019-12-29](#2351---2019-12-29)
- [2.35.0 - 2019-12-29](#2350---2019-12-29)
- [2.34.0 - 2019-11-02](#2340---2019-11-02)
- [2.33.2 - 2019-10-06](#2332---2019-10-06)
- [2.33.1 - 2019-10-06](#2331---2019-10-06)
- [2.33.0 - 2019-09-26](#2330---2019-09-26)
- [2.32.3 - 2019-09-18](#2323---2019-09-18)
- [2.32.2 - 2019-09-15](#2322---2019-09-15)
- [2.32.1 - 2019-09-14](#2321---2019-09-14)
- [2.32.0 - 2019-09-12](#2320---2019-09-12)
- [2.31.1 - 2019-08-30](#2311---2019-08-30)
- [2.31.0](#2310)
- [2.30.2](#2302)
- [2.30.1](#2301)
- [2.30.0](#2300)
- [2.29.0](#2290)
- [2.28.2](#2282)
- [2.28.1](#2281)
- [2.28.0](#2280)
- [2.27.0](#2270)
- [2.26.4](#2264)
- [2.26.3](#2263)
- [2.26.2](#2262)
- [2.26.1](#2261)
- [2.26.0](#2260)
- [2.25.3](#2253)
- [2.25.2](#2252)
- [2.25.1](#2251)
- [2.25.0](#2250)
- [2.24.0](#2240)
- [2.23.2](#2232)
- [2.23.1](#2231)
- [2.23.0](#2230)
- [2.22.4](#2224)
- [2.22.3](#2223)
- [2.22.2](#2222)
- [2.22.1](#2221)
- [2.22.0](#2220)
- [2.21.3](#2213)
- [2.21.2](#2212)
- [2.21.1](#2211)
- [2.21.0](#2210)
- [2.20.2](#2202)
- [2.20.1](#2201)
- [2.20.0](#2200)
- [2.19.0](#2190)
- [2.18.1](#2181)
- [2.18.0](#2180)
- [2.17.2](#2172)
- [2.17.1](#2171)
- [2.17.0](#2170)
- [2.16.1](#2161)
- [2.16.0](#2160)
- [2.15.4](#2154)
- [2.15.3](#2153)
- [2.15.2](#2152)
- [2.15.1](#2151)
- [2.15.0](#2150)
- [2.14.1](#2141)
- [2.14.0](#2140)
- [2.13.2](#2132)
- [2.13.1](#2131)
- [2.13.0](#2130)
- [2.12.1](#2121)
- [2.12.0](#2120)
- [2.11.0](#2110)
- [2.10.2](#2102)
- [2.10.1](#2101)
- [2.10.0](#2100)
- [2.9.0](#290)
- [2.8.1](#281)
- [2.8.0](#280)
- [2.7.2](#272)
- [2.7.1](#271)
- [2.7.0](#270)
- [2.6.3](#263)
- [2.6.2](#262)
- [2.6.1](#261)
- [2.6.0](#260)
- [2.5.4](#254)
- [2.5.3](#253)
- [2.5.2](#252)
- [2.5.1](#251)
- [2.5.0](#250)
- [2.4.0](#240)
- [2.3.0](#230)
- [2.2.1](#221)
- [2.2.0](#220)
- [2.1.5](#215)
- [2.1.3 / 2.1.4](#213--214)
- [2.1.2](#212)
- [2.1.1](#211)
- [2.1.0](#210)
- [2.0.3](#203)
- [2.0.2](#202)
- [2.0.1](#201)
- [2.0.0](#200)
- [New Functionality](#new-functionality)
- [Breaking Changes in 2.0.0](#breaking-changes-in-200)
- [Gmail Delegation Management Removed](#gmail-delegation-management-removed)
- [Functions Removed](#functions-removed)
- [Functions Aliased](#functions-aliased)

***

# PSGSuite - ChangeLog

## 2.37.0 - 2022-03-18

* Added `Move-GSCalendarEvent` function for changing event ownership/organizer.

## 2.36.5 - 2020-11-01

* [Issue #331](https://github.com/scrthq/PSGSuite/issues/331)
Expand Down
92 changes: 92 additions & 0 deletions PSGSuite/Public/Calendar/Move-GSCalendarEvent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
function Move-GSCalendarEvent {
<#
.SYNOPSIS
Moves an event to a new calendar (updates the Organizer).

.DESCRIPTION
Moves an event to a new calendar (updates the Organizer).

.PARAMETER CalendarID
The Id of the source calendar.

Defaults to the user's primary calendar.

.PARAMETER EventID
The unique Id of the event to update

.PARAMETER DestinationCalendarId
The Id of the destination calendar.

.PARAMETER User
The primary email or UserID of the user. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config.

Defaults to the AdminEmail in the config.

User must have access to both calendars. Recommend using admin.

.PARAMETER SendUpdates
Whether to send update notifications to the attendees.

Possible values are:
* "none" - No notifications are sent.
* "externalOnly" - Notifications are sent to non-Google Calendar guests only.
* "all" - Notifications are sent to all guests.

.EXAMPLE
Move-GSCalendarEvent -CalendarId [email protected] -EventId bcfgr7j83oqpv8174bnamv63pj -DestinationCalendarId [email protected]

Moves the event with eventId "bcfgr7j83oqpv8174bnamv63pj" from calendar "[email protected]" to calendar "[email protected]"
#>
[OutputType('Google.Apis.Calendar.v3.Data.Event')]
[cmdletbinding(DefaultParameterSetName = "AttendeeEmails")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's no parameter sets defined, so while this doesn't hurt anything, it doesn't do anything either.

Param
(
[parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
[Alias('Id')]
[String]
$EventId,
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[String]
$CalendarId = "primary",
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[Alias("PrimaryEmail", "UserKey", "Mail")]
[ValidateNotNullOrEmpty()]
[String]
$User = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $false)]
[String]
$DestinationCalendarId,
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)]
[ValidateSet("none", "all", "externalOnly")]
[String]
$SendUpdates = "none"
)
Process {
try {
if ($Uuser -ceq 'me') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a typo, I would assume this should be $User

$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/calendar'
ServiceType = 'Google.Apis.Calendar.v3.CalendarService'
User = $User
}
$service = New-GoogleService @serviceParams
Write-Verbose "Moving Calendar Event '$EventId' on calendar '$CalendarId' for user '$User' to calendar '$DestinationCalendarId'"
$request = $service.Events.Move($CalendarId, $EventId, $DestinationCalendarId)
$request.SendUpdates = $SendUpdates
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'CalendarId' -Value $DestinationCalendarId -PassThru
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ All other functions are either intact or have an alias included to support backw

[Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md)

#### 2.37.0 - 2022-03-18

* Added `Move-GSCalendarEvent` function for changing event ownership/organizer.

#### 2.36.4 - 2020-03-20

* [Issue #270](https://github.com/scrthq/PSGSuite/issues/270)
Expand Down