From f561cfa9c7252ab4751d65279c4733479a153f6a Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Sat, 30 Mar 2019 01:51:54 -0500 Subject: [PATCH 1/3] v2.25.4 - resolve #169 and resolve #168 --- CHANGELOG.md | 9 ++ PSGSuite/PSGSuite.psd1 | 2 +- PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 | 3 +- .../Public/Helpers/Add-GSUserLocation.ps1 | 113 ++++++++++++++++++ PSGSuite/Public/Users/New-GSUser.ps1 | 20 ++++ PSGSuite/Public/Users/Update-GSUser.ps1 | 22 ++++ README.md | 10 +- 7 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 49250903..a8c53123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog * [Changelog](#changelog) + * [2.25.4](#2254) * [2.25.3](#2253) * [2.25.2](#2252) * [2.25.1](#2251) @@ -81,6 +82,14 @@ *** +## 2.25.4 + +* [Issue #169](https://github.com/scrthq/PSGSuite/issues/169) + * Fixed: `Get-GSGmailMessage` fails to download attachments containing invalid characters (e.g. `:`) +* [Issue #168](https://github.com/scrthq/PSGSuite/issues/168) + * Added: `Add-GSUserLocation` + * Updated: `New-GSUser` and `Update-GSUser` to add in Location support + ## 2.25.3 * Miscellaneous diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index c29121c7..547da6fb 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.25.3' + ModuleVersion = '2.25.4' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 index 3a2f7947..dc5a2dba 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailMessage.ps1 @@ -98,7 +98,8 @@ function Get-GSGmailMessage { $resPath = Resolve-Path $SaveAttachmentsTo $attachments = $parsed.Attachments foreach ($att in $attachments) { - $fileName = Join-Path $resPath $att.FileName + $cleanedName = $att.FileName -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" + $fileName = Join-Path $resPath $cleanedName Write-Verbose "Saving attachment to path '$fileName'" $stream = [System.IO.File]::Create($fileName) $att.ContentObject.DecodeTo($stream) diff --git a/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 b/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 new file mode 100644 index 00000000..14559d40 --- /dev/null +++ b/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 @@ -0,0 +1,113 @@ +function Add-GSUserLocation { + <# + .SYNOPSIS + Builds a Location object to use when creating or updating a User + + .DESCRIPTION + Builds a Location object to use when creating or updating a User + + .PARAMETER Area + Textual location. This is most useful for display purposes to concisely describe the location. For example, "Mountain View, CA", "Near Seattle", "US-NYC-9TH 9A209A" + + .PARAMETER BuildingId + Building Identifier. + + .PARAMETER CustomType + Custom Type. + + .PARAMETER DeskCode + Most specific textual code of individual desk location. + + .PARAMETER FloorName + Floor name/number. + + .PARAMETER FloorSection + Floor section. More specific location within the floor. For example, if a floor is divided into sections "A", "B", and "C", this field would identify one of those values. + + .PARAMETER Type + Each entry can have a type which indicates standard types of that entry. For example location could be of types default and desk. In addition to standard type, an entry can have a custom type and can give it any name. Such types should have "custom" as type and also have a customType value. + + Acceptable values are: + * "custom" + * "default" + * "desk" + + .PARAMETER InputObject + Used for pipeline input of an existing Location object to strip the extra attributes and prevent errors + + .EXAMPLE + Add-GSUserLocation -Area "Bellevue, WA" -BuildingId '30' -CustomType "LemonadeStand" -Type custom + + Adds a custom user location. + #> + [CmdletBinding()] + Param + ( + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $Area, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $BuildingId, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $CustomType, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $DeskCode, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $FloorName, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $FloorSection, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [ValidateSet('custom', 'default', 'desk')] + [String] + $Type, + [Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "InputObject")] + [Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]] + $InputObject + ) + Begin { + $propsToWatch = @( + 'Area' + 'BuildingId' + 'CustomType' + 'DeskCode' + 'FloorName' + 'FloorSection' + 'Type' + ) + } + Process { + try { + switch ($PSCmdlet.ParameterSetName) { + Fields { + $obj = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserLocation' + foreach ($prop in $PSBoundParameters.Keys | Where-Object {$obj.PSObject.Properties.Name -contains $_}) { + $obj.$prop = $PSBoundParameters[$prop] + } + $obj + } + InputObject { + foreach ($iObj in $InputObject) { + $obj = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserLocation' + foreach ($prop in $iObj.PSObject.Properties.Name | Where-Object {$obj.PSObject.Properties.Name -contains $_ -and $propsToWatch -contains $_}) { + $obj.$prop = $iObj.$prop + } + $obj + } + } + } + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } +} diff --git a/PSGSuite/Public/Users/New-GSUser.ps1 b/PSGSuite/Public/Users/New-GSUser.ps1 index aef428ef..d92581ca 100644 --- a/PSGSuite/Public/Users/New-GSUser.ps1 +++ b/PSGSuite/Public/Users/New-GSUser.ps1 @@ -45,6 +45,11 @@ function New-GSUser { This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId[]' object type. You can create objects of this type easily by using the function 'Add-GSUserExternalId' + .PARAMETER Locations + The Location objects of the user + + This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]' object type. You can create objects of this type easily by using the function 'Add-GSUserLocation' + .PARAMETER Organizations The organization objects of the user @@ -146,6 +151,9 @@ function New-GSUser { [Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId[]] $ExternalIds, [parameter(Mandatory = $false)] + [Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]] + $Locations, + [parameter(Mandatory = $false)] [Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization[]] $Organizations, [parameter(Mandatory = $false)] @@ -224,6 +232,18 @@ function New-GSUser { } $body.ExternalIds = $extIdList } + Locations { + if ($null -ne $Locations) { + $locationList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserLocation]' + foreach ($loc in $Locations) { + $locationList.Add($loc) + } + $body.Locations = $locationList + } + else { + $toClear['locations'] = $null + } + } Organizations { $orgList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization]' foreach ($organization in $Organizations) { diff --git a/PSGSuite/Public/Users/Update-GSUser.ps1 b/PSGSuite/Public/Users/Update-GSUser.ps1 index 2678078e..3c22fb93 100644 --- a/PSGSuite/Public/Users/Update-GSUser.ps1 +++ b/PSGSuite/Public/Users/Update-GSUser.ps1 @@ -50,6 +50,13 @@ function Update-GSUser { To CLEAR all values for a user, pass `$null` as the value for this parameter. + .PARAMETER Locations + The Location objects of the user + + This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]' object type. You can create objects of this type easily by using the function 'Add-GSUserLocation' + + To CLEAR all values for a user, pass `$null` as the value for this parameter. + .PARAMETER Organizations The organization objects of the user @@ -157,6 +164,9 @@ function Update-GSUser { [Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId[]] $ExternalIds, [parameter(Mandatory = $false)] + [Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]] + $Locations, + [parameter(Mandatory = $false)] [Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization[]] $Organizations, [parameter(Mandatory = $false)] @@ -267,6 +277,18 @@ function Update-GSUser { $toClear['externalIds'] = $null } } + Locations { + if ($null -ne $Locations) { + $locationList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserLocation]' + foreach ($loc in $Locations) { + $locationList.Add($loc) + } + $body.Locations = $locationList + } + else { + $toClear['locations'] = $null + } + } Organizations { if ($null -ne $Organizations) { $orgList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization]' diff --git a/README.md b/README.md index 725f0dfc..d6d836da 100644 --- a/README.md +++ b/README.md @@ -139,10 +139,18 @@ Update-GSCalendarResource Update-GSResource Update-GSSheetValue Export-GSSheet ``` -### Most recent change +### Most recent changes [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) +#### 2.25.4 + +* [Issue #169](https://github.com/scrthq/PSGSuite/issues/169) + * Fixed: `Get-GSGmailMessage` fails to download attachments containing invalid characters (e.g. `:`) +* [Issue #168](https://github.com/scrthq/PSGSuite/issues/168) + * Added: `Add-GSUserLocation` + * Updated: `New-GSUser` and `Update-GSUser` to add in Location support + #### 2.25.3 * Miscellaneous From b1ad2c3407faf87976dbcb77edf9034f98d3cdbd Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Sat, 30 Mar 2019 02:37:30 -0500 Subject: [PATCH 2/3] added pipeline support for multiple functions --- CHANGELOG.md | 6 ++-- PSGSuite/PSGSuite.psd1 | 2 +- .../Classroom/Add-GSCourseParticipant.ps1 | 4 +-- .../Classroom/Confirm-GSCourseInvitation.ps1 | 8 ++--- .../Classroom/Get-GSCourseParticipant.ps1 | 8 ++--- .../Classroom/Get-GSStudentGuardian.ps1 | 6 ++-- .../Get-GSStudentGuardianInvitation.ps1 | 6 ++-- PSGSuite/Public/Classroom/New-GSCourse.ps1 | 6 ++-- .../Public/Classroom/New-GSCourseAlias.ps1 | 26 +++++++------- .../Classroom/New-GSCourseInvitation.ps1 | 6 ++-- .../New-GSStudentGuardianInvitation.ps1 | 6 ++-- PSGSuite/Public/Classroom/Remove-GSCourse.ps1 | 6 ++-- .../Public/Classroom/Remove-GSCourseAlias.ps1 | 6 ++-- .../Classroom/Remove-GSCourseInvitation.ps1 | 6 ++-- .../Classroom/Remove-GSCourseParticipant.ps1 | 6 ++-- .../Classroom/Remove-GSStudentGuardian.ps1 | 6 ++-- .../Revoke-GSStudentGuardianInvitation.ps1 | 6 ++-- PSGSuite/Public/Classroom/Update-GSCourse.ps1 | 8 ++--- PSGSuite/Public/Drive/Add-GSDocContent.ps1 | 14 ++++---- .../Public/Drive/Add-GSDrivePermission.ps1 | 4 +-- PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 | 4 +-- PSGSuite/Public/Drive/Export-GSDriveFile.ps1 | 4 +-- PSGSuite/Public/Drive/Get-GSDriveFile.ps1 | 4 +-- PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 | 4 +-- .../Public/Drive/Get-GSDrivePermission.ps1 | 4 +-- PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 | 4 +-- PSGSuite/Public/Drive/New-GSDriveFile.ps1 | 4 +-- PSGSuite/Public/Drive/New-GSTeamDrive.ps1 | 4 +-- PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 | 4 +-- .../Public/Drive/Remove-GSDrivePermission.ps1 | 22 ++++++------ PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 | 14 ++++---- PSGSuite/Public/Drive/Set-GSDocContent.ps1 | 26 +++++++------- .../Public/Drive/Start-GSDriveFileUpload.ps1 | 18 +++++----- PSGSuite/Public/Drive/Update-GSDriveFile.ps1 | 4 +-- PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 | 4 +-- PSGSuite/Public/Gmail/Add-GSGmailFilter.ps1 | 4 +-- .../Gmail/Add-GSGmailForwardingAddress.ps1 | 4 +-- .../Get-GSGmailAutoForwardingSettings.ps1 | 4 +-- PSGSuite/Public/Gmail/Get-GSGmailFilter.ps1 | 4 +-- .../Gmail/Get-GSGmailForwardingAddress.ps1 | 4 +-- .../Public/Gmail/Get-GSGmailImapSettings.ps1 | 4 +-- PSGSuite/Public/Gmail/Get-GSGmailLabel.ps1 | 4 +-- .../Public/Gmail/Get-GSGmailPopSettings.ps1 | 4 +-- .../Public/Gmail/Get-GSGmailSMIMEInfo.ps1 | 6 ++-- .../Gmail/Get-GSGmailVacationSettings.ps1 | 4 +-- PSGSuite/Public/Gmail/New-GSGmailLabel.ps1 | 5 ++- .../Public/Gmail/New-GSGmailSMIMEInfo.ps1 | 6 ++-- .../Public/Gmail/Remove-GSGmailFilter.ps1 | 16 ++++----- PSGSuite/Public/Gmail/Remove-GSGmailLabel.ps1 | 4 +-- .../Public/Gmail/Remove-GSGmailSMIMEInfo.ps1 | 18 +++++----- PSGSuite/Public/Gmail/Send-GmailMessage.ps1 | 26 +++++++------- PSGSuite/Public/Sheets/Clear-GSSheet.ps1 | 4 +-- PSGSuite/Public/Sheets/Copy-GSSheet.ps1 | 4 +-- PSGSuite/Public/Sheets/Export-GSSheet.ps1 | 6 ++-- PSGSuite/Public/Sheets/Get-GSSheetInfo.ps1 | 4 +-- PSGSuite/Public/Sheets/Import-GSSheet.ps1 | 34 +++++++++---------- PSGSuite/Public/Sheets/New-GSSheet.ps1 | 4 +-- PSGSuite/Public/Tasks/Clear-GSTasklist.ps1 | 16 ++++----- PSGSuite/Public/Tasks/Get-GSTask.ps1 | 6 ++-- PSGSuite/Public/Tasks/Get-GSTasklist.ps1 | 6 ++-- PSGSuite/Public/Tasks/Move-GSTask.ps1 | 6 ++-- PSGSuite/Public/Tasks/New-GSTask.ps1 | 6 ++-- PSGSuite/Public/Tasks/New-GSTasklist.ps1 | 6 ++-- PSGSuite/Public/Tasks/Remove-GSTask.ps1 | 18 +++++----- PSGSuite/Public/Tasks/Remove-GSTasklist.ps1 | 16 ++++----- PSGSuite/Public/Tasks/Update-GSTask.ps1 | 6 ++-- PSGSuite/Public/Tasks/Update-GSTasklist.ps1 | 6 ++-- .../Public/URL Shortener/Get-GSShortUrl.ps1 | 4 +-- .../Public/URL Shortener/New-GSShortUrl.ps1 | 4 +-- 69 files changed, 219 insertions(+), 324 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c53123..b1009abd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog * [Changelog](#changelog) - * [2.25.4](#2254) + * [2.26.0](#2260) * [2.25.3](#2253) * [2.25.2](#2252) * [2.25.1](#2251) @@ -82,13 +82,15 @@ *** -## 2.25.4 +## 2.26.0 * [Issue #169](https://github.com/scrthq/PSGSuite/issues/169) * Fixed: `Get-GSGmailMessage` fails to download attachments containing invalid characters (e.g. `:`) * [Issue #168](https://github.com/scrthq/PSGSuite/issues/168) * Added: `Add-GSUserLocation` * Updated: `New-GSUser` and `Update-GSUser` to add in Location support +* Miscellaneous + * Improved pipeline support for the `User` parameter across all pertinent functions, i.e. Drive, Calendar, Gmail, Sheets & Tasks APIs. ## 2.25.3 diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index 547da6fb..e4af04eb 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.25.4' + ModuleVersion = '2.26.0' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Public/Classroom/Add-GSCourseParticipant.ps1 b/PSGSuite/Public/Classroom/Add-GSCourseParticipant.ps1 index 131a3e84..c00252b4 100644 --- a/PSGSuite/Public/Classroom/Add-GSCourseParticipant.ps1 +++ b/PSGSuite/Public/Classroom/Add-GSCourseParticipant.ps1 @@ -51,7 +51,7 @@ function Add-GSCourseParticipant { [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -64,8 +64,6 @@ function Add-GSCourseParticipant { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($part in $Student | Where-Object {-not [String]::IsNullOrEmpty($_)}) { try { $body = New-Object 'Google.Apis.Classroom.v1.Data.Student' diff --git a/PSGSuite/Public/Classroom/Confirm-GSCourseInvitation.ps1 b/PSGSuite/Public/Classroom/Confirm-GSCourseInvitation.ps1 index a5547b59..1b0fcf5a 100644 --- a/PSGSuite/Public/Classroom/Confirm-GSCourseInvitation.ps1 +++ b/PSGSuite/Public/Classroom/Confirm-GSCourseInvitation.ps1 @@ -18,14 +18,14 @@ function Confirm-GSCourseInvitation { [cmdletbinding()] Param ( - [parameter(Mandatory = $true)] + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] [String] $Id, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] [String] $User ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -38,8 +38,6 @@ function Confirm-GSCourseInvitation { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { Write-Verbose "Accepting Invitation '$Id' for user '$User'" $request = $service.Invitations.Accept($Id) diff --git a/PSGSuite/Public/Classroom/Get-GSCourseParticipant.ps1 b/PSGSuite/Public/Classroom/Get-GSCourseParticipant.ps1 index be10dbca..9b507146 100644 --- a/PSGSuite/Public/Classroom/Get-GSCourseParticipant.ps1 +++ b/PSGSuite/Public/Classroom/Get-GSCourseParticipant.ps1 @@ -46,7 +46,7 @@ function Get-GSCourseParticipant { [cmdletbinding(DefaultParameterSetName = "List")] Param ( - [parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName)] + [parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName = $true)] [ValidateNotNullOrEmpty()] [alias('Id')] [String] @@ -61,14 +61,14 @@ function Get-GSCourseParticipant { [parameter(Mandatory = $false,ParameterSetName = "Get")] [String[]] $Student, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail, [parameter(Mandatory = $false)] [String[]] $Fields = '*' ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -85,8 +85,6 @@ function Get-GSCourseParticipant { User = $User } $service = New-GoogleService @serviceParams - } - Process { switch ($PSCmdlet.ParameterSetName) { Get { foreach ($part in $Student) { diff --git a/PSGSuite/Public/Classroom/Get-GSStudentGuardian.ps1 b/PSGSuite/Public/Classroom/Get-GSStudentGuardian.ps1 index 5777a765..ee87454b 100644 --- a/PSGSuite/Public/Classroom/Get-GSStudentGuardian.ps1 +++ b/PSGSuite/Public/Classroom/Get-GSStudentGuardian.ps1 @@ -38,11 +38,11 @@ function Get-GSStudentGuardian { [Alias('Guardian')] [String[]] $GuardianId, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -55,8 +55,6 @@ function Get-GSStudentGuardian { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($stuId in $StudentId) { try { if ($stuId -ne '-') { diff --git a/PSGSuite/Public/Classroom/Get-GSStudentGuardianInvitation.ps1 b/PSGSuite/Public/Classroom/Get-GSStudentGuardianInvitation.ps1 index 714fce1a..e6840677 100644 --- a/PSGSuite/Public/Classroom/Get-GSStudentGuardianInvitation.ps1 +++ b/PSGSuite/Public/Classroom/Get-GSStudentGuardianInvitation.ps1 @@ -56,11 +56,11 @@ function Get-GSStudentGuardianInvitation { [parameter(Mandatory = $false,ParameterSetName = "List")] [Google.Apis.Classroom.v1.UserProfilesResource+GuardianInvitationsResource+ListRequest+StatesEnum[]] $States, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -73,8 +73,6 @@ function Get-GSStudentGuardianInvitation { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($stuId in $StudentId) { try { if ($stuId -ne '-') { diff --git a/PSGSuite/Public/Classroom/New-GSCourse.ps1 b/PSGSuite/Public/Classroom/New-GSCourse.ps1 index 125648d1..cb2e9c76 100644 --- a/PSGSuite/Public/Classroom/New-GSCourse.ps1 +++ b/PSGSuite/Public/Classroom/New-GSCourse.ps1 @@ -87,11 +87,11 @@ function New-GSCourse { [ValidateSet('PROVISIONED','ACTIVE','ARCHIVED','DECLINED')] [String] $CourseState, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -104,8 +104,6 @@ function New-GSCourse { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { Write-Verbose "Creating new Course '$Name'" $body = New-Object 'Google.Apis.Classroom.v1.Data.Course' diff --git a/PSGSuite/Public/Classroom/New-GSCourseAlias.ps1 b/PSGSuite/Public/Classroom/New-GSCourseAlias.ps1 index 85bb5b78..74d412bc 100644 --- a/PSGSuite/Public/Classroom/New-GSCourseAlias.ps1 +++ b/PSGSuite/Public/Classroom/New-GSCourseAlias.ps1 @@ -41,23 +41,11 @@ function New-GSCourseAlias { [ValidateSet('Domain','Project')] [String] $Scope = $(if($Alias -match "^p\:"){'Project'}else{'Domain'}), - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) Begin { - if ($User -ceq 'me') { - $User = $Script:PSGSuite.AdminEmail - } - elseif ($User -notlike "*@*.*") { - $User = "$($User)@$($Script:PSGSuite.Domain)" - } - $serviceParams = @{ - Scope = 'https://www.googleapis.com/auth/classroom.courses' - ServiceType = 'Google.Apis.Classroom.v1.ClassroomService' - User = $User - } - $service = New-GoogleService @serviceParams $formatted = if ($Alias -match "^(d\:|p\:)") { $Alias $Scope = if ($Alias -match "^d\:") { @@ -80,6 +68,18 @@ function New-GSCourseAlias { } } Process { + if ($User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/classroom.courses' + ServiceType = 'Google.Apis.Classroom.v1.ClassroomService' + User = $User + } + $service = New-GoogleService @serviceParams try { Write-Verbose "Creating new Alias '$Alias' for Course '$CourseId' at '$Scope' scope" $body = New-Object 'Google.Apis.Classroom.v1.Data.CourseAlias' -Property @{ diff --git a/PSGSuite/Public/Classroom/New-GSCourseInvitation.ps1 b/PSGSuite/Public/Classroom/New-GSCourseInvitation.ps1 index b3523eef..4d777b64 100644 --- a/PSGSuite/Public/Classroom/New-GSCourseInvitation.ps1 +++ b/PSGSuite/Public/Classroom/New-GSCourseInvitation.ps1 @@ -44,11 +44,11 @@ function New-GSCourseInvitation { [ValidateSet('STUDENT','TEACHER','OWNER')] [String] $Role = 'STUDENT', - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -61,8 +61,6 @@ function New-GSCourseInvitation { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($U in $UserId) { try { if ( -not ($U -as [decimal])) { diff --git a/PSGSuite/Public/Classroom/New-GSStudentGuardianInvitation.ps1 b/PSGSuite/Public/Classroom/New-GSStudentGuardianInvitation.ps1 index d4764132..8bbeab6f 100644 --- a/PSGSuite/Public/Classroom/New-GSStudentGuardianInvitation.ps1 +++ b/PSGSuite/Public/Classroom/New-GSStudentGuardianInvitation.ps1 @@ -43,11 +43,11 @@ function New-GSStudentGuardianInvitation { [Alias('Guardian')] [String] $GuardianEmail, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -60,8 +60,6 @@ function New-GSStudentGuardianInvitation { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ( -not ($StudentId -as [decimal])) { if ($StudentId -ceq 'me') { diff --git a/PSGSuite/Public/Classroom/Remove-GSCourse.ps1 b/PSGSuite/Public/Classroom/Remove-GSCourse.ps1 index 84c096b4..fa35efbc 100644 --- a/PSGSuite/Public/Classroom/Remove-GSCourse.ps1 +++ b/PSGSuite/Public/Classroom/Remove-GSCourse.ps1 @@ -22,11 +22,11 @@ function Remove-GSCourse { [Alias('Alias')] [String] $Id, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -39,8 +39,6 @@ function Remove-GSCourse { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($PSCmdlet.ShouldProcess("Removing Course '$Id'")) { Write-Verbose "Removing Course '$Id'" diff --git a/PSGSuite/Public/Classroom/Remove-GSCourseAlias.ps1 b/PSGSuite/Public/Classroom/Remove-GSCourseAlias.ps1 index 4f662aad..c93c6aab 100644 --- a/PSGSuite/Public/Classroom/Remove-GSCourseAlias.ps1 +++ b/PSGSuite/Public/Classroom/Remove-GSCourseAlias.ps1 @@ -27,11 +27,11 @@ function Remove-GSCourseAlias { [parameter(Mandatory = $true,Position = 1)] [String] $CourseId, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -44,8 +44,6 @@ function Remove-GSCourseAlias { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($PSCmdlet.ShouldProcess("Removing Alias '$Alias' for Course '$CourseId'")) { Write-Verbose "Removing Alias '$Alias' for Course '$CourseId'" diff --git a/PSGSuite/Public/Classroom/Remove-GSCourseInvitation.ps1 b/PSGSuite/Public/Classroom/Remove-GSCourseInvitation.ps1 index 99047ce4..95133c85 100644 --- a/PSGSuite/Public/Classroom/Remove-GSCourseInvitation.ps1 +++ b/PSGSuite/Public/Classroom/Remove-GSCourseInvitation.ps1 @@ -21,11 +21,11 @@ function Remove-GSCourseInvitation { [parameter(Mandatory = $true,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true)] [String[]] $Id, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -38,8 +38,6 @@ function Remove-GSCourseInvitation { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($I in $Id) { try { if ($PSCmdlet.ShouldProcess("Removing Invitation '$I'")) { diff --git a/PSGSuite/Public/Classroom/Remove-GSCourseParticipant.ps1 b/PSGSuite/Public/Classroom/Remove-GSCourseParticipant.ps1 index 64871c49..ea6c887d 100644 --- a/PSGSuite/Public/Classroom/Remove-GSCourseParticipant.ps1 +++ b/PSGSuite/Public/Classroom/Remove-GSCourseParticipant.ps1 @@ -46,11 +46,11 @@ function Remove-GSCourseParticipant { [parameter(Mandatory = $false)] [String[]] $Teacher, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -63,8 +63,6 @@ function Remove-GSCourseParticipant { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($part in $Student) { try { if ( -not ($part -as [decimal])) { diff --git a/PSGSuite/Public/Classroom/Remove-GSStudentGuardian.ps1 b/PSGSuite/Public/Classroom/Remove-GSStudentGuardian.ps1 index baaee2b7..16354d10 100644 --- a/PSGSuite/Public/Classroom/Remove-GSStudentGuardian.ps1 +++ b/PSGSuite/Public/Classroom/Remove-GSStudentGuardian.ps1 @@ -35,11 +35,11 @@ function Remove-GSStudentGuardian { [Alias('Guardian')] [String] $GuardianId, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -52,8 +52,6 @@ function Remove-GSStudentGuardian { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ( -not ($StudentId -as [decimal])) { if ($StudentId -ceq 'me') { diff --git a/PSGSuite/Public/Classroom/Revoke-GSStudentGuardianInvitation.ps1 b/PSGSuite/Public/Classroom/Revoke-GSStudentGuardianInvitation.ps1 index f4a94be3..96eea37e 100644 --- a/PSGSuite/Public/Classroom/Revoke-GSStudentGuardianInvitation.ps1 +++ b/PSGSuite/Public/Classroom/Revoke-GSStudentGuardianInvitation.ps1 @@ -50,11 +50,11 @@ function Revoke-GSStudentGuardianInvitation { [Alias('Invitation','InviteId','Invite')] [String[]] $InvitationId, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -67,8 +67,6 @@ function Revoke-GSStudentGuardianInvitation { User = $User } $service = New-GoogleService @serviceParams - } - Process { if ( -not ($StudentId -as [decimal])) { if ($StudentId -ceq 'me') { $StudentId = $Script:PSGSuite.AdminEmail diff --git a/PSGSuite/Public/Classroom/Update-GSCourse.ps1 b/PSGSuite/Public/Classroom/Update-GSCourse.ps1 index 31ec3dae..f47c845e 100644 --- a/PSGSuite/Public/Classroom/Update-GSCourse.ps1 +++ b/PSGSuite/Public/Classroom/Update-GSCourse.ps1 @@ -85,11 +85,14 @@ function Update-GSCourse { [ValidateSet('PROVISIONED','ACTIVE','ARCHIVED','DECLINED')] [String] $CourseState, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [String] $User = $Script:PSGSuite.AdminEmail ) Begin { + $UpdateMask = @() + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -102,9 +105,6 @@ function Update-GSCourse { User = $User } $service = New-GoogleService @serviceParams - $UpdateMask = @() - } - Process { try { Write-Verbose "Updating Course ID '$Id'" $body = New-Object 'Google.Apis.Classroom.v1.Data.Course' diff --git a/PSGSuite/Public/Drive/Add-GSDocContent.ps1 b/PSGSuite/Public/Drive/Add-GSDocContent.ps1 index c4170d65..642e81a9 100644 --- a/PSGSuite/Public/Drive/Add-GSDocContent.ps1 +++ b/PSGSuite/Public/Drive/Add-GSDocContent.ps1 @@ -37,6 +37,13 @@ function Add-GSDocContent { $User = $Script:PSGSuite.AdminEmail ) Begin { + $service = New-GoogleService @serviceParams + $stream = New-Object 'System.IO.MemoryStream' + $writer = New-Object 'System.IO.StreamWriter' $stream + $currentContent = Get-GSDocContent -FileID $FileID -User $User -Verbose:$false + $concatStrings = @($currentContent) + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -48,13 +55,6 @@ function Add-GSDocContent { ServiceType = 'Google.Apis.Drive.v3.DriveService' User = $User } - $service = New-GoogleService @serviceParams - $stream = New-Object 'System.IO.MemoryStream' - $writer = New-Object 'System.IO.StreamWriter' $stream - $currentContent = Get-GSDocContent -FileID $FileID -User $User -Verbose:$false - $concatStrings = @($currentContent) - } - Process { foreach ($string in $Value) { $concatStrings += $string } diff --git a/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 b/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 index d69a3131..853c4718 100644 --- a/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 +++ b/PSGSuite/Public/Drive/Add-GSDrivePermission.ps1 @@ -118,7 +118,7 @@ function Add-GSDrivePermission { [switch] $UseDomainAdminAccess ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -131,8 +131,6 @@ function Add-GSDrivePermission { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($Role -eq "Owner" -and !$TransferOwnership) { if ($PSCmdlet.ShouldProcess("Confirm transfer of ownership of FileId '$FileID' from user '$User' to user '$EmailAddress'")) { diff --git a/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 index 73b5f1c1..3c2bd3ec 100644 --- a/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Copy-GSDriveFile.ps1 @@ -87,6 +87,8 @@ function Copy-GSDriveFile { elseif ($Fields) { $fs = $Fields } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -99,8 +101,6 @@ function Copy-GSDriveFile { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Drive.v3.Data.File' if ($Name) { diff --git a/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 index ae2bec98..74b6c66d 100644 --- a/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 @@ -122,6 +122,8 @@ function Export-GSDriveFile { SVG = "image/svg+xml" TSV = "text/tab-separated-values" } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -134,8 +136,6 @@ function Export-GSDriveFile { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $request = $service.Files.Export($FileID,($mimeHash[$Type])) if ($fs) { diff --git a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 index bec44857..0ecb1a24 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFile.ps1 @@ -82,6 +82,8 @@ function Get-GSDriveFile { elseif ($Fields) { $fs = $Fields } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -94,8 +96,6 @@ function Get-GSDriveFile { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { foreach ($file in $FileId) { $request = $service.Files.Get($file) diff --git a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 index 385be969..cf440d21 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 @@ -96,6 +96,8 @@ function Get-GSDriveFileList { $PSBoundParameters['Filter'] = "'$ParentFolderId' in parents" } } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -108,8 +110,6 @@ function Get-GSDriveFileList { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $request = $service.Files.List() $request.SupportsTeamDrives = $true diff --git a/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 b/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 index c1fd986c..2441c0bb 100644 --- a/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDrivePermission.ps1 @@ -45,7 +45,7 @@ function Get-GSDrivePermission { [Int] $PageSize = "100" ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -58,8 +58,6 @@ function Get-GSDrivePermission { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($PermissionId) { foreach ($per in $PermissionId) { diff --git a/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 index 5efc3a32..56cd11cd 100644 --- a/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/Get-GSTeamDrive.ps1 @@ -44,7 +44,7 @@ function Get-GSTeamDrive { [Int] $PageSize = "100" ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -57,8 +57,6 @@ function Get-GSTeamDrive { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { switch ($PSCmdlet.ParameterSetName) { Get { diff --git a/PSGSuite/Public/Drive/New-GSDriveFile.ps1 b/PSGSuite/Public/Drive/New-GSDriveFile.ps1 index 3f975d55..75bc5f6d 100644 --- a/PSGSuite/Public/Drive/New-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/New-GSDriveFile.ps1 @@ -124,6 +124,8 @@ function New-GSDriveFile { elseif ($Fields) { $fs = $Fields } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -136,8 +138,6 @@ function New-GSDriveFile { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Drive.v3.Data.File' if ($MimeType) { diff --git a/PSGSuite/Public/Drive/New-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/New-GSTeamDrive.ps1 index 2eb5bbd5..d059806b 100644 --- a/PSGSuite/Public/Drive/New-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/New-GSTeamDrive.ps1 @@ -120,7 +120,7 @@ function New-GSTeamDrive { [Switch] $CanShare ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -133,8 +133,6 @@ function New-GSTeamDrive { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive' $capabilities = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive+CapabilitiesData' diff --git a/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 index 86ea74ee..dc0908f7 100644 --- a/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Remove-GSDriveFile.ps1 @@ -30,7 +30,7 @@ function Remove-GSDriveFile { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -43,8 +43,6 @@ function Remove-GSDriveFile { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($file in $FileId) { try { if ($PSCmdlet.ShouldProcess("Deleting File Id '$file' from user '$User'")) { diff --git a/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 b/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 index e66e2f1f..bbf46f94 100644 --- a/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 +++ b/PSGSuite/Public/Drive/Remove-GSDrivePermission.ps1 @@ -2,21 +2,21 @@ function Remove-GSDrivePermission { <# .SYNOPSIS Removes a permission from a Drive file - + .DESCRIPTION Removes a permission from a Drive file - + .PARAMETER User The email or unique Id of the user whose Drive file permission you are trying to get Defaults to the AdminEmail user - + .PARAMETER FileId The unique Id of the Drive file - + .PARAMETER PermissionId The unique Id of the permission you are trying to remove. - + .EXAMPLE Remove-GSDrivePermission -FileId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' -PermissionID 'sdfadsfsdafasd' @@ -33,16 +33,16 @@ function Remove-GSDrivePermission { [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] [Alias('Owner','PrimaryEmail','UserKey','Mail')] [string] - $User = $Script:PSGSuite.AdminEmail, + $User = $Script:PSGSuite.AdminEmail, [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] [String] - $FileId, + $FileId, [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] - [Alias('Id')] + [Alias('Id')] [String] $PermissionId ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -55,8 +55,6 @@ function Remove-GSDrivePermission { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($PSCmdlet.ShouldProcess("Removing Drive Permission Id '$PermissionId' from FileId '$FileID'")) { $request = $service.Permissions.Delete($FileId,$PermissionId) @@ -74,4 +72,4 @@ function Remove-GSDrivePermission { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 index 77e35036..f99355b3 100644 --- a/PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 @@ -2,18 +2,18 @@ function Remove-GSTeamDrive { <# .SYNOPSIS Removes a Team Drive - + .DESCRIPTION Removes a Team Drive - + .PARAMETER TeamDriveId The Id of the Team Drive to remove - + .PARAMETER User The email or unique Id of the user with permission to delete the Team Drive Defaults to the AdminEmail user - + .EXAMPLE Remove-TeamDrive -TeamDriveId "0AJ8Xjq3FcdCKUk9PVA" -Confirm:$false @@ -31,7 +31,7 @@ function Remove-GSTeamDrive { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -44,8 +44,6 @@ function Remove-GSTeamDrive { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { foreach ($id in $TeamDriveId) { if ($PSCmdlet.ShouldProcess("Deleting Team Drive '$id' from user '$User'")) { @@ -65,4 +63,4 @@ function Remove-GSTeamDrive { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Drive/Set-GSDocContent.ps1 b/PSGSuite/Public/Drive/Set-GSDocContent.ps1 index 54015ec4..fadf3986 100644 --- a/PSGSuite/Public/Drive/Set-GSDocContent.ps1 +++ b/PSGSuite/Public/Drive/Set-GSDocContent.ps1 @@ -2,21 +2,21 @@ function Set-GSDocContent { <# .SYNOPSIS Sets the content of a Google Doc. This overwrites any existing content on the Doc - + .DESCRIPTION Sets the content of a Google Doc. This overwrites any existing content on the Doc - + .PARAMETER FileID The unique Id of the file to set content on - + .PARAMETER Value The content to set - + .PARAMETER User The email or unique Id of the owner of the Drive file Defaults to the AdminEmail user - + .EXAMPLE $logStrings | Set-GSDocContent -FileId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' @@ -24,7 +24,7 @@ function Set-GSDocContent { #> [CmdLetBinding()] Param - ( + ( [parameter(Mandatory = $true,Position = 0)] [String] $FileID, @@ -37,6 +37,12 @@ function Set-GSDocContent { $User = $Script:PSGSuite.AdminEmail ) Begin { + $service = New-GoogleService @serviceParams + $stream = New-Object 'System.IO.MemoryStream' + $writer = New-Object 'System.IO.StreamWriter' $stream + $concatStrings = @() + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -48,12 +54,6 @@ function Set-GSDocContent { ServiceType = 'Google.Apis.Drive.v3.DriveService' User = $User } - $service = New-GoogleService @serviceParams - $stream = New-Object 'System.IO.MemoryStream' - $writer = New-Object 'System.IO.StreamWriter' $stream - $concatStrings = @() - } - Process { foreach ($string in $Value) { $concatStrings += $string } @@ -82,4 +82,4 @@ function Set-GSDocContent { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 index b7995913..36580b6f 100644 --- a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 @@ -80,6 +80,15 @@ function Start-GSDriveFileUpload { $User = $Script:PSGSuite.AdminEmail ) Begin { + $taskList = [System.Collections.ArrayList]@() + $fullTaskList = [System.Collections.ArrayList]@() + $start = Get-Date + $folIdHash = @{} + $throttleCount = 0 + $totalThrottleCount = 0 + $totalFiles = 0 + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -92,15 +101,6 @@ function Start-GSDriveFileUpload { User = $User } $service = New-GoogleService @serviceParams - $taskList = [System.Collections.ArrayList]@() - $fullTaskList = [System.Collections.ArrayList]@() - $start = Get-Date - $folIdHash = @{} - $throttleCount = 0 - $totalThrottleCount = 0 - $totalFiles = 0 - } - Process { try { foreach ($file in $Path) { $details = Get-Item $file diff --git a/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 index 6d6dde8d..bb13a20a 100644 --- a/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Update-GSDriveFile.ps1 @@ -104,6 +104,8 @@ function Update-GSDriveFile { elseif ($Fields) { $fs = $Fields } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -116,8 +118,6 @@ function Update-GSDriveFile { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Drive.v3.Data.File' if ($Name) { diff --git a/PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 index c825d221..c6f3167c 100644 --- a/PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 @@ -119,7 +119,7 @@ function Update-GSTeamDrive { [Switch] $CanShare ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -132,8 +132,6 @@ function Update-GSTeamDrive { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive' $capabilities = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive+CapabilitiesData' diff --git a/PSGSuite/Public/Gmail/Add-GSGmailFilter.ps1 b/PSGSuite/Public/Gmail/Add-GSGmailFilter.ps1 index b7371594..7b2cc705 100644 --- a/PSGSuite/Public/Gmail/Add-GSGmailFilter.ps1 +++ b/PSGSuite/Public/Gmail/Add-GSGmailFilter.ps1 @@ -108,7 +108,7 @@ [Switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -121,8 +121,6 @@ User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Gmail.v1.Data.Filter' $action = New-Object 'Google.Apis.Gmail.v1.Data.FilterAction' diff --git a/PSGSuite/Public/Gmail/Add-GSGmailForwardingAddress.ps1 b/PSGSuite/Public/Gmail/Add-GSGmailForwardingAddress.ps1 index 928685b0..66ac8ab7 100644 --- a/PSGSuite/Public/Gmail/Add-GSGmailForwardingAddress.ps1 +++ b/PSGSuite/Public/Gmail/Add-GSGmailForwardingAddress.ps1 @@ -33,7 +33,7 @@ function Add-GSGmailForwardingAddress { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -46,8 +46,6 @@ function Add-GSGmailForwardingAddress { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { foreach ($fwd in $ForwardingAddress) { $body = New-Object 'Google.Apis.Gmail.v1.Data.ForwardingAddress' -Property @{ diff --git a/PSGSuite/Public/Gmail/Get-GSGmailAutoForwardingSettings.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailAutoForwardingSettings.ps1 index d91b64d2..58a90302 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailAutoForwardingSettings.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailAutoForwardingSettings.ps1 @@ -26,7 +26,7 @@ function Get-GSGmailAutoForwardingSettings { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -39,8 +39,6 @@ function Get-GSGmailAutoForwardingSettings { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $request = $service.Users.Settings.GetAutoForwarding($User) Write-Verbose "Getting AutoForwarding settings for user '$User'" diff --git a/PSGSuite/Public/Gmail/Get-GSGmailFilter.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailFilter.ps1 index 46b68cf7..72bf39aa 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailFilter.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailFilter.ps1 @@ -37,7 +37,7 @@ function Get-GSGmailFilter { [switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -50,8 +50,6 @@ function Get-GSGmailFilter { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($FilterId) { foreach ($fil in $FilterId) { diff --git a/PSGSuite/Public/Gmail/Get-GSGmailForwardingAddress.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailForwardingAddress.ps1 index 5558decf..62a4f561 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailForwardingAddress.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailForwardingAddress.ps1 @@ -33,7 +33,7 @@ function Get-GSGmailForwardingAddress { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -46,8 +46,6 @@ function Get-GSGmailForwardingAddress { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($ForwardingAddress) { foreach ($fwd in $ForwardingAddress) { diff --git a/PSGSuite/Public/Gmail/Get-GSGmailImapSettings.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailImapSettings.ps1 index fd20eef4..a804d9b6 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailImapSettings.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailImapSettings.ps1 @@ -26,7 +26,7 @@ function Get-GSGmailImapSettings { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -39,8 +39,6 @@ function Get-GSGmailImapSettings { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $request = $service.Users.Settings.GetImap($User) Write-Verbose "Getting IMAP settings for user '$User'" diff --git a/PSGSuite/Public/Gmail/Get-GSGmailLabel.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailLabel.ps1 index df77ec60..e3229348 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailLabel.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailLabel.ps1 @@ -33,7 +33,7 @@ function Get-GSGmailLabel { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -46,8 +46,6 @@ function Get-GSGmailLabel { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($LabelId) { foreach ($label in $LabelId) { diff --git a/PSGSuite/Public/Gmail/Get-GSGmailPopSettings.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailPopSettings.ps1 index fc02b585..199b96c8 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailPopSettings.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailPopSettings.ps1 @@ -26,7 +26,7 @@ function Get-GSGmailPopSettings { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -39,8 +39,6 @@ function Get-GSGmailPopSettings { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $request = $service.Users.Settings.GetPop($User) Write-Verbose "Getting POP settings for user '$User'" diff --git a/PSGSuite/Public/Gmail/Get-GSGmailSMIMEInfo.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailSMIMEInfo.ps1 index c8e7e2a2..8f3646a1 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailSMIMEInfo.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailSMIMEInfo.ps1 @@ -34,13 +34,13 @@ function Get-GSGmailSMIMEInfo { [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [string[]] $Id, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail")] [ValidateNotNullOrEmpty()] [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -53,8 +53,6 @@ function Get-GSGmailSMIMEInfo { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($PSBoundParameters.Keys -contains 'Id') { foreach ($I in $Id) { diff --git a/PSGSuite/Public/Gmail/Get-GSGmailVacationSettings.ps1 b/PSGSuite/Public/Gmail/Get-GSGmailVacationSettings.ps1 index d5ec8001..46315b8e 100644 --- a/PSGSuite/Public/Gmail/Get-GSGmailVacationSettings.ps1 +++ b/PSGSuite/Public/Gmail/Get-GSGmailVacationSettings.ps1 @@ -26,7 +26,7 @@ function Get-GSGmailVacationSettings { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -39,8 +39,6 @@ function Get-GSGmailVacationSettings { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $request = $service.Users.Settings.GetVacation($User) Write-Verbose "Getting Vacation settings for user '$User'" diff --git a/PSGSuite/Public/Gmail/New-GSGmailLabel.ps1 b/PSGSuite/Public/Gmail/New-GSGmailLabel.ps1 index bd5068f1..e0672d0c 100644 --- a/PSGSuite/Public/Gmail/New-GSGmailLabel.ps1 +++ b/PSGSuite/Public/Gmail/New-GSGmailLabel.ps1 @@ -270,6 +270,8 @@ function New-GSGmailLabel { White = '#ffffff' YellowOrange = '#ffad47' } + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -282,9 +284,6 @@ function New-GSGmailLabel { User = $User } $service = New-GoogleService @serviceParams - } - - Process { $body = New-Object 'Google.Apis.Gmail.v1.Data.Label' foreach ($prop in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_}) { $body.$prop = $PSBoundParameters[$prop] diff --git a/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 b/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 index 7e729441..05a10727 100644 --- a/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 +++ b/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 @@ -53,13 +53,13 @@ function New-GSGmailSMIMEInfo { [parameter(Mandatory = $false)] [Switch] $IsDefault, - [parameter(Mandatory = $true)] + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail")] [ValidateNotNullOrEmpty()] [string] $User ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -72,8 +72,6 @@ function New-GSGmailSMIMEInfo { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Gmail.v1.Data.SmimeInfo' foreach ($key in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_}) { diff --git a/PSGSuite/Public/Gmail/Remove-GSGmailFilter.ps1 b/PSGSuite/Public/Gmail/Remove-GSGmailFilter.ps1 index 3d56ce15..023763f6 100644 --- a/PSGSuite/Public/Gmail/Remove-GSGmailFilter.ps1 +++ b/PSGSuite/Public/Gmail/Remove-GSGmailFilter.ps1 @@ -2,21 +2,21 @@ <# .SYNOPSIS Removes a Gmail filter - + .DESCRIPTION Removes a Gmail filter - + .PARAMETER User The primary email of the user to remove the filter from Defaults to the AdminEmail user - + .PARAMETER FilterId The unique Id of the filter to remove - + .PARAMETER Raw If $true, returns the raw response. If not passed or -Raw:$false, response is formatted as a flat object for readability - + .EXAMPLE Remove-GSGmailFilter -FilterId ANe1Bmj5l3089jd3k1eQbY90g9rXswjS03LVOw @@ -38,7 +38,7 @@ [switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -51,8 +51,6 @@ User = $User } $service = New-GoogleService @serviceParams - } - Process { try { foreach ($fil in $FilterId) { if ($PSCmdlet.ShouldProcess("Deleting Filter Id '$fil' from user '$User'")) { @@ -72,4 +70,4 @@ } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Gmail/Remove-GSGmailLabel.ps1 b/PSGSuite/Public/Gmail/Remove-GSGmailLabel.ps1 index 257ad47e..3cd6056c 100644 --- a/PSGSuite/Public/Gmail/Remove-GSGmailLabel.ps1 +++ b/PSGSuite/Public/Gmail/Remove-GSGmailLabel.ps1 @@ -32,7 +32,7 @@ function Remove-GSGmailLabel { [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -45,8 +45,6 @@ function Remove-GSGmailLabel { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($label in $LabelId) { try { if ($PSCmdlet.ShouldProcess("Deleting Label Id '$label' from user '$User'")) { diff --git a/PSGSuite/Public/Gmail/Remove-GSGmailSMIMEInfo.ps1 b/PSGSuite/Public/Gmail/Remove-GSGmailSMIMEInfo.ps1 index e8d7813d..f2989e93 100644 --- a/PSGSuite/Public/Gmail/Remove-GSGmailSMIMEInfo.ps1 +++ b/PSGSuite/Public/Gmail/Remove-GSGmailSMIMEInfo.ps1 @@ -2,21 +2,21 @@ function Remove-GSGmailSMIMEInfo { <# .SYNOPSIS Removes Gmail S/MIME info - + .DESCRIPTION Removes Gmail S/MIME info - + .PARAMETER SendAsEmail The email address that appears in the "From:" header for mail sent using this alias. - + .PARAMETER Id The immutable ID for the SmimeInfo - + .PARAMETER User The user's email address Defaults to the AdminEmail user - + .EXAMPLE Remove-GSGmailSMIMEInfo -SendAsEmail 'joe@otherdomain.com' -Id 1008396210820120578939 -User joe@domain.com @@ -31,13 +31,13 @@ function Remove-GSGmailSMIMEInfo { [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] [string[]] $Id, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail")] [ValidateNotNullOrEmpty()] [string] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -50,8 +50,6 @@ function Remove-GSGmailSMIMEInfo { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($I in $Id) { try { if ($PSCmdlet.ShouldProcess("Removing S/MIME Id '$I' of SendAsEmail '$SendAsEmail' for user '$User'")) { @@ -70,4 +68,4 @@ function Remove-GSGmailSMIMEInfo { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Gmail/Send-GmailMessage.ps1 b/PSGSuite/Public/Gmail/Send-GmailMessage.ps1 index 0169c98f..cca6fcac 100644 --- a/PSGSuite/Public/Gmail/Send-GmailMessage.ps1 +++ b/PSGSuite/Public/Gmail/Send-GmailMessage.ps1 @@ -2,36 +2,36 @@ <# .SYNOPSIS Sends a Gmail message - + .DESCRIPTION Sends a Gmail message. Designed for parity with Send-GmailMessage - + .PARAMETER From The primary email of the user that is sending the message. This MUST be a user account owned by the customer, as the Gmail Service must be built under this user's context and will fail if a group or alias is passed instead Defaults to the AdminEmail user - + .PARAMETER Subject The subject of the email - + .PARAMETER Body The email body. Supports HTML when used in conjunction with the -BodyAsHtml parameter - + .PARAMETER To The To recipient(s) of the email - + .PARAMETER CC The Cc recipient(s) of the email - + .PARAMETER BCC The Bcc recipient(s) of the email - + .PARAMETER Attachments The attachment(s) of the email - + .PARAMETER BodyAsHtml If passed, renders the HTML content of the body on send - + .EXAMPLE Send-GmailMessage -From Joe -To john.doe@domain.com -Subject "New Pricing Models" -Body $body -BodyAsHtml -Attachments 'C:\Reports\PricingModel_2018.xlsx' @@ -41,7 +41,7 @@ Param ( [parameter(Mandatory = $false)] - [Alias("PrimaryEmail","UserKey","Mail")] + [Alias("PrimaryEmail","UserKey","Mail","User")] [ValidateNotNullOrEmpty()] [String] $From = $Script:PSGSuite.AdminEmail, @@ -102,7 +102,7 @@ $messageParams.Add("BCC",@($BCC)) } if ($Attachments) { - $messageParams.Add("Attachment",@($Attachments)) + $messageParams.Add("Attachment",@($Attachments)) } if ($BodyAsHtml) { $messageParams.Add("BodyAsHtml",$true) @@ -125,4 +125,4 @@ } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Sheets/Clear-GSSheet.ps1 b/PSGSuite/Public/Sheets/Clear-GSSheet.ps1 index 9deb0204..3a7acde1 100644 --- a/PSGSuite/Public/Sheets/Clear-GSSheet.ps1 +++ b/PSGSuite/Public/Sheets/Clear-GSSheet.ps1 @@ -49,7 +49,7 @@ function Clear-GSSheet { [switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -62,8 +62,6 @@ function Clear-GSSheet { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($SheetName) { if ($Range -like "'*'!*") { diff --git a/PSGSuite/Public/Sheets/Copy-GSSheet.ps1 b/PSGSuite/Public/Sheets/Copy-GSSheet.ps1 index 5494392c..e5c8d685 100644 --- a/PSGSuite/Public/Sheets/Copy-GSSheet.ps1 +++ b/PSGSuite/Public/Sheets/Copy-GSSheet.ps1 @@ -53,7 +53,7 @@ function Copy-GSSheet { [switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -66,8 +66,6 @@ function Copy-GSSheet { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($PSCmdlet.ParameterSetName -eq "CreateNewSheet") { if ($NewSheetTitle) { diff --git a/PSGSuite/Public/Sheets/Export-GSSheet.ps1 b/PSGSuite/Public/Sheets/Export-GSSheet.ps1 index 5d55d4dd..ee06cb7d 100644 --- a/PSGSuite/Public/Sheets/Export-GSSheet.ps1 +++ b/PSGSuite/Public/Sheets/Export-GSSheet.ps1 @@ -111,6 +111,9 @@ function Export-GSSheet { $Launch ) Begin { + $values = New-Object 'System.Collections.Generic.List[System.Collections.Generic.IList[Object]]' + } + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -123,9 +126,6 @@ function Export-GSSheet { User = $User } $service = New-GoogleService @serviceParams - $values = New-Object 'System.Collections.Generic.List[System.Collections.Generic.IList[Object]]' - } - Process { try { if ($Value) { $finalArray = $([pscustomobject]@{Value = "$Value"}) diff --git a/PSGSuite/Public/Sheets/Get-GSSheetInfo.ps1 b/PSGSuite/Public/Sheets/Get-GSSheetInfo.ps1 index 26df5301..f47f317b 100644 --- a/PSGSuite/Public/Sheets/Get-GSSheetInfo.ps1 +++ b/PSGSuite/Public/Sheets/Get-GSSheetInfo.ps1 @@ -68,7 +68,7 @@ function Get-GSSheetInfo { [switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -81,8 +81,6 @@ function Get-GSSheetInfo { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($SheetName) { if ($Range -like "'*'!*") { diff --git a/PSGSuite/Public/Sheets/Import-GSSheet.ps1 b/PSGSuite/Public/Sheets/Import-GSSheet.ps1 index 62e008c5..69bc042e 100644 --- a/PSGSuite/Public/Sheets/Import-GSSheet.ps1 +++ b/PSGSuite/Public/Sheets/Import-GSSheet.ps1 @@ -2,35 +2,35 @@ function Import-GSSheet { <# .SYNOPSIS Imports data from a Sheet as if it was a CSV - + .DESCRIPTION Imports data from a Sheet as if it was a CSV - + .PARAMETER SpreadsheetId The unique Id of the SpreadSheet to import data from - + .PARAMETER SheetName The name of the Sheet to import data from - + .PARAMETER User The owner of the SpreadSheet - + .PARAMETER Range The specific range to import data from - + .PARAMETER RowStart The starting row of data. Useful if the headers for your table are not in Row 1 of the Sheet - + .PARAMETER Headers Allows you to define the headers for the rows on the sheet, in case there is no header row - + .PARAMETER DateTimeRenderOption How to render the DateTime cells Available values are: * "FORMATTED_STRING" (Default) * "SERIAL_NUMBER" - + .PARAMETER ValueRenderOption How to render the value cells and formula cells @@ -38,7 +38,7 @@ function Import-GSSheet { * "FORMATTED_VALUE" (Default) * "UNFORMATTED_VALUE" * "FORMULA" - + .PARAMETER MajorDimension The major dimension that results should use. @@ -48,17 +48,17 @@ function Import-GSSheet { * "ROWS" (Default) * "COLUMNS" * "DIMENSION_UNSPECIFIED" - + .PARAMETER As Whether to return the result set as an array of PSObjects or an array of DataRows Available values are: * "PSObject" (Default) * "DataRow" - + .PARAMETER Raw If $true, return the raw response, otherwise, return a flattened response for readability - + .EXAMPLE Import-GSSheet -SpreadsheetId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' -SheetName Sheet1 -RowStart 2 -Range 'B:C' @@ -66,7 +66,7 @@ function Import-GSSheet { #> [cmdletbinding(DefaultParameterSetName = "Import")] Param - ( + ( [parameter(Mandatory = $true)] [String] $SpreadsheetId, @@ -108,7 +108,7 @@ function Import-GSSheet { [switch] $Raw ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -121,8 +121,6 @@ function Import-GSSheet { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { if ($SheetName) { if ($Range -like "'*'!*") { @@ -203,4 +201,4 @@ function Import-GSSheet { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Sheets/New-GSSheet.ps1 b/PSGSuite/Public/Sheets/New-GSSheet.ps1 index 0fc2dedf..28539007 100644 --- a/PSGSuite/Public/Sheets/New-GSSheet.ps1 +++ b/PSGSuite/Public/Sheets/New-GSSheet.ps1 @@ -37,7 +37,7 @@ function New-GSSheet { [Switch] $Launch ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -50,8 +50,6 @@ function New-GSSheet { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { $body = New-Object 'Google.Apis.Sheets.v4.Data.Spreadsheet' $body.Properties = New-Object 'Google.Apis.Sheets.v4.Data.SpreadsheetProperties' -Property @{ diff --git a/PSGSuite/Public/Tasks/Clear-GSTasklist.ps1 b/PSGSuite/Public/Tasks/Clear-GSTasklist.ps1 index c88db3ff..dae1e98c 100644 --- a/PSGSuite/Public/Tasks/Clear-GSTasklist.ps1 +++ b/PSGSuite/Public/Tasks/Clear-GSTasklist.ps1 @@ -2,18 +2,18 @@ function Clear-GSTasklist { <# .SYNOPSIS Clears all completed tasks from the specified task list. The affected tasks will be marked as 'hidden' and no longer be returned by default when retrieving all tasks for a task list - + .DESCRIPTION Clears all completed tasks from the specified task list. The affected tasks will be marked as 'hidden' and no longer be returned by default when retrieving all tasks for a task list - + .PARAMETER Tasklist The unique Id of the Tasklist to clear - + .PARAMETER User The User who owns the Tasklist. Defaults to the AdminUser's email. - + .EXAMPLE Clear-GSTasklist -Tasklist 'MTA3NjIwMjA1NTEzOTk0MjQ0OTk6NTMyNDY5NDk1NDM5MzMxO' -Confirm:$false @@ -26,13 +26,13 @@ function Clear-GSTasklist { [Alias('Id')] [String[]] $Tasklist, - [parameter(Mandatory = $false,Position = 1)] + [parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -45,8 +45,6 @@ function Clear-GSTasklist { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($list in $Tasklist) { try { if ($PSCmdlet.ShouldProcess("Clearing Tasklist '$list' for user '$User'")) { @@ -65,4 +63,4 @@ function Clear-GSTasklist { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Tasks/Get-GSTask.ps1 b/PSGSuite/Public/Tasks/Get-GSTask.ps1 index 5fc97cc4..cca7729c 100644 --- a/PSGSuite/Public/Tasks/Get-GSTask.ps1 +++ b/PSGSuite/Public/Tasks/Get-GSTask.ps1 @@ -43,7 +43,7 @@ function Get-GSTask { [parameter(Mandatory = $true,Position = 1)] [String] $Tasklist, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] @@ -78,7 +78,7 @@ function Get-GSTask { [Int] $PageSize ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -91,8 +91,6 @@ function Get-GSTask { User = $User } $service = New-GoogleService @serviceParams - } - Process { switch ($PSCmdlet.ParameterSetName) { Get { foreach ($T in $Task) { diff --git a/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 b/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 index 7d1a9f55..cf3734f5 100644 --- a/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 +++ b/PSGSuite/Public/Tasks/Get-GSTasklist.ps1 @@ -37,7 +37,7 @@ function Get-GSTasklist { [Alias('Id')] [String[]] $Tasklist, - [parameter(Mandatory = $false,Position = 1)] + [parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] @@ -48,7 +48,7 @@ function Get-GSTasklist { [Int] $PageSize ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -61,8 +61,6 @@ function Get-GSTasklist { User = $User } $service = New-GoogleService @serviceParams - } - Process { switch ($PSCmdlet.ParameterSetName) { Get { foreach ($list in $Tasklist) { diff --git a/PSGSuite/Public/Tasks/Move-GSTask.ps1 b/PSGSuite/Public/Tasks/Move-GSTask.ps1 index e6c1f33f..967a8d27 100644 --- a/PSGSuite/Public/Tasks/Move-GSTask.ps1 +++ b/PSGSuite/Public/Tasks/Move-GSTask.ps1 @@ -45,13 +45,13 @@ function Move-GSTask { [parameter(Mandatory = $false)] [String] $Previous, - [parameter(Mandatory = $false,Position = 1)] + [parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -64,8 +64,6 @@ function Move-GSTask { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($T in $Task) { try { Write-Verbose "Moving Task '$T' for user '$User'" diff --git a/PSGSuite/Public/Tasks/New-GSTask.ps1 b/PSGSuite/Public/Tasks/New-GSTask.ps1 index fe6872d9..960fda23 100644 --- a/PSGSuite/Public/Tasks/New-GSTask.ps1 +++ b/PSGSuite/Public/Tasks/New-GSTask.ps1 @@ -69,13 +69,13 @@ function New-GSTask { [parameter(Mandatory = $false)] [String] $Previous, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -88,8 +88,6 @@ function New-GSTask { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($T in $Title) { try { Write-Verbose "Creating Task '$T' on Tasklist '$Tasklist' for user '$User'" diff --git a/PSGSuite/Public/Tasks/New-GSTasklist.ps1 b/PSGSuite/Public/Tasks/New-GSTasklist.ps1 index c9329c6a..49fd4d67 100644 --- a/PSGSuite/Public/Tasks/New-GSTasklist.ps1 +++ b/PSGSuite/Public/Tasks/New-GSTasklist.ps1 @@ -26,13 +26,13 @@ function New-GSTasklist { [parameter(Mandatory = $true,Position = 0)] [String[]] $Title, - [parameter(Mandatory = $false,Position = 1)] + [parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -45,8 +45,6 @@ function New-GSTasklist { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($list in $Title) { try { Write-Verbose "Creating Tasklist '$list' for user '$User'" diff --git a/PSGSuite/Public/Tasks/Remove-GSTask.ps1 b/PSGSuite/Public/Tasks/Remove-GSTask.ps1 index f65e7286..0535ee38 100644 --- a/PSGSuite/Public/Tasks/Remove-GSTask.ps1 +++ b/PSGSuite/Public/Tasks/Remove-GSTask.ps1 @@ -2,21 +2,21 @@ function Remove-GSTask { <# .SYNOPSIS Deletes the authenticated user's specified task - + .DESCRIPTION Deletes the authenticated user's specified task - + .PARAMETER Task The unique Id of the Task to delete - + .PARAMETER Tasklist The unique Id of the Tasklist where the Task is - + .PARAMETER User The User who owns the Tasklist. Defaults to the AdminUser's email. - + .EXAMPLE Remove-GSTask -Task 'MTA3NjIwMjA1NTEzOTk0MjQ0OTk6MDow' -Tasklist 'MTA3NjIwMjA1NTEzOTk0MjQ0OTk6NTMyNDY5NDk1NDM5MzMxO' -Confirm:$false @@ -32,13 +32,13 @@ function Remove-GSTask { [parameter(Mandatory = $true,Position = 1)] [String] $Tasklist, - [parameter(Mandatory = $false,Position = 1)] + [parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -51,8 +51,6 @@ function Remove-GSTask { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($T in $Task) { try { if ($PSCmdlet.ShouldProcess("Removing Task '$T' from Tasklist '$Tasklist' for user '$User'")) { @@ -71,4 +69,4 @@ function Remove-GSTask { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Tasks/Remove-GSTasklist.ps1 b/PSGSuite/Public/Tasks/Remove-GSTasklist.ps1 index d37343fd..4137df22 100644 --- a/PSGSuite/Public/Tasks/Remove-GSTasklist.ps1 +++ b/PSGSuite/Public/Tasks/Remove-GSTasklist.ps1 @@ -2,18 +2,18 @@ function Remove-GSTasklist { <# .SYNOPSIS Deletes the authenticated user's specified task list - + .DESCRIPTION Deletes the authenticated user's specified task list - + .PARAMETER Tasklist The unique Id of the Tasklist to remove - + .PARAMETER User The User who owns the Tasklist. Defaults to the AdminUser's email. - + .EXAMPLE Remove-GSTasklist -Tasklist 'MTA3NjIwMjA1NTEzOTk0MjQ0OTk6NTMyNDY5NDk1NDM5MzMxO' -Confirm:$false @@ -26,13 +26,13 @@ function Remove-GSTasklist { [Alias('Id')] [String[]] $Tasklist, - [parameter(Mandatory = $false,Position = 1)] + [parameter(Mandatory = $false,Position = 1,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -45,8 +45,6 @@ function Remove-GSTasklist { User = $User } $service = New-GoogleService @serviceParams - } - Process { foreach ($list in $Tasklist) { try { if ($PSCmdlet.ShouldProcess("Removing Tasklist '$list' for user '$User'")) { @@ -65,4 +63,4 @@ function Remove-GSTasklist { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Tasks/Update-GSTask.ps1 b/PSGSuite/Public/Tasks/Update-GSTask.ps1 index 1cfde230..c953f340 100644 --- a/PSGSuite/Public/Tasks/Update-GSTask.ps1 +++ b/PSGSuite/Public/Tasks/Update-GSTask.ps1 @@ -75,13 +75,13 @@ function Update-GSTask { [parameter(Mandatory = $false)] [String] $Previous, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -94,8 +94,6 @@ function Update-GSTask { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { Write-Verbose "Updating Task '$Task' on Tasklist '$Tasklist' for user '$User'" $body = New-Object 'Google.Apis.Tasks.v1.Data.Task' diff --git a/PSGSuite/Public/Tasks/Update-GSTasklist.ps1 b/PSGSuite/Public/Tasks/Update-GSTasklist.ps1 index c4f79405..92d536ef 100644 --- a/PSGSuite/Public/Tasks/Update-GSTasklist.ps1 +++ b/PSGSuite/Public/Tasks/Update-GSTasklist.ps1 @@ -32,13 +32,13 @@ function Update-GSTasklist { [parameter(Mandatory = $true,Position = 1)] [String] $Title, - [parameter(Mandatory = $false)] + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias("PrimaryEmail","UserKey","Mail","Email")] [ValidateNotNullOrEmpty()] [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -51,8 +51,6 @@ function Update-GSTasklist { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { Write-Verbose "Updating Tasklist '$list' to Title '$Title' for user '$User'" $body = New-Object 'Google.Apis.Tasks.v1.Data.TaskList' -Property @{ diff --git a/PSGSuite/Public/URL Shortener/Get-GSShortUrl.ps1 b/PSGSuite/Public/URL Shortener/Get-GSShortUrl.ps1 index 60e54d09..7739aeb2 100644 --- a/PSGSuite/Public/URL Shortener/Get-GSShortUrl.ps1 +++ b/PSGSuite/Public/URL Shortener/Get-GSShortUrl.ps1 @@ -44,7 +44,7 @@ function Get-GSShortUrl { [string] $Projection = "Full" ) - Begin { + Process { if ($ShortUrl) { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail @@ -59,8 +59,6 @@ function Get-GSShortUrl { } $service = New-GoogleService @serviceParams } - } - Process { try { if ($ShortUrl) { foreach ($S in $ShortUrl) { diff --git a/PSGSuite/Public/URL Shortener/New-GSShortUrl.ps1 b/PSGSuite/Public/URL Shortener/New-GSShortUrl.ps1 index 0d253dce..5de548f8 100644 --- a/PSGSuite/Public/URL Shortener/New-GSShortUrl.ps1 +++ b/PSGSuite/Public/URL Shortener/New-GSShortUrl.ps1 @@ -32,7 +32,7 @@ function New-GSShortUrl { [String] $User = $Script:PSGSuite.AdminEmail ) - Begin { + Process { if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail } @@ -45,8 +45,6 @@ function New-GSShortUrl { User = $User } $service = New-GoogleService @serviceParams - } - Process { try { foreach ($L in $LongUrl) { Write-Verbose "Creating short Url for '$L'" From cb1f347f33cbcb6d6cfc067fdfee369dab07fff9 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Sat, 30 Mar 2019 02:37:51 -0500 Subject: [PATCH 3/3] added pipeline support for multiple functions --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6d836da..4f142438 100644 --- a/README.md +++ b/README.md @@ -143,13 +143,15 @@ Update-GSSheetValue Export-GSSheet [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) -#### 2.25.4 +#### 2.26.0 * [Issue #169](https://github.com/scrthq/PSGSuite/issues/169) * Fixed: `Get-GSGmailMessage` fails to download attachments containing invalid characters (e.g. `:`) * [Issue #168](https://github.com/scrthq/PSGSuite/issues/168) * Added: `Add-GSUserLocation` * Updated: `New-GSUser` and `Update-GSUser` to add in Location support +* Miscellaneous + * Improved pipeline support for the `User` parameter across all pertinent functions, i.e. Drive, Calendar, Gmail, Sheets & Tasks APIs. #### 2.25.3