From 3b77528a8bcc15bc14cdce76b7777ee5e31f8d14 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Thu, 27 Jun 2019 22:45:58 -0500 Subject: [PATCH] converted remaining TeamDrive functions to the new Drive namespace and added Show/Hide-GSDrive functions for #197 --- CHANGELOG.md | 22 ++++-- PSGSuite/Aliases/PSGSuite.Aliases.ps1 | 4 + PSGSuite/Public/Drive/Hide-GSDrive.ps1 | 64 ++++++++++++++++ .../{New-GSTeamDrive.ps1 => New-GSDrive.ps1} | 69 ++++++++--------- ...ove-GSTeamDrive.ps1 => Remove-GSDrive.ps1} | 30 ++++---- PSGSuite/Public/Drive/Show-GSDrive.ps1 | 64 ++++++++++++++++ ...ate-GSTeamDrive.ps1 => Update-GSDrive.ps1} | 74 ++++++++++--------- 7 files changed, 238 insertions(+), 89 deletions(-) create mode 100644 PSGSuite/Public/Drive/Hide-GSDrive.ps1 rename PSGSuite/Public/Drive/{New-GSTeamDrive.ps1 => New-GSDrive.ps1} (67%) rename PSGSuite/Public/Drive/{Remove-GSTeamDrive.ps1 => Remove-GSDrive.ps1} (65%) create mode 100644 PSGSuite/Public/Drive/Show-GSDrive.ps1 rename PSGSuite/Public/Drive/{Update-GSTeamDrive.ps1 => Update-GSDrive.ps1} (66%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b98aa3a0..9bbf8bbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ -* [PSGSuite - ChangeLog](#psgsuite---changelog) +* [PSGSuite - ChangeLog](#PSGSuite---ChangeLog) + * [2.29.0](#2290) * [2.28.2](#2282) * [2.28.1](#2281) * [2.28.0](#2280) @@ -80,16 +81,25 @@ * [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) + * [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.29.0 + +* [Issue #201](https://github.com/scrthq/PSGSuite/issues/201) + * Fixed: Fields parameter on remaining `*-GSDriveFile` functions +* [Issue #197](https://github.com/scrthq/PSGSuite/issues/197) + * Updated: All remaining `*-TeamDrive` functions now use the new Drives namespace. All previous functions names have been converted to aliases to maintain backwards compatibility. + * Added: `Hide-GSDrive` + * Added: `Show-GSDrive` + ## 2.28.2 * [Issue #194](https://github.com/scrthq/PSGSuite/issues/194) diff --git a/PSGSuite/Aliases/PSGSuite.Aliases.ps1 b/PSGSuite/Aliases/PSGSuite.Aliases.ps1 index 4942df43..30fb2822 100644 --- a/PSGSuite/Aliases/PSGSuite.Aliases.ps1 +++ b/PSGSuite/Aliases/PSGSuite.Aliases.ps1 @@ -1,3 +1,4 @@ +# Alias => => => => => => => => Function @{ 'Add-GSDriveFilePermissions' = 'Add-GSDrivePermission' 'Export-PSGSuiteConfiguration' = 'Set-PSGSuiteConfig' @@ -33,10 +34,13 @@ 'Import-PSGSuiteConfiguration' = 'Get-PSGSuiteConfig' 'Move-GSGmailMessageToTrash' = 'Remove-GSGmailMessage' 'New-GSCalendarResource' = 'New-GSResource' + 'New-GSTeamDrive' = 'New-GSDrive' 'Remove-GSGmailMessageFromTrash' = 'Restore-GSGmailMessage' + 'Remove-GSTeamDrive' = 'Remove-GSDrive' 'Set-PSGSuiteDefaultDomain' = 'Switch-PSGSuiteConfig' 'Switch-PSGSuiteDomain' = 'Switch-PSGSuiteConfig' 'Update-GSCalendarResource' = 'Update-GSResource' 'Update-GSGmailSendAsSettings' = 'Update-GSGmailSendAsAlias' 'Update-GSSheetValue' = 'Export-GSSheet' + 'Update-GSTeamDrive' = 'Update-GSDrive' } diff --git a/PSGSuite/Public/Drive/Hide-GSDrive.ps1 b/PSGSuite/Public/Drive/Hide-GSDrive.ps1 new file mode 100644 index 00000000..5001a68f --- /dev/null +++ b/PSGSuite/Public/Drive/Hide-GSDrive.ps1 @@ -0,0 +1,64 @@ +function Hide-GSDrive { + <# + .SYNOPSIS + Hides a Shared Drive from the default view + + .DESCRIPTION + Hides a Shared Drive from the default view + + .PARAMETER DriveId + The unique Id of the Shared Drive to hide + + .PARAMETER User + The email or unique Id of the user who you'd like to hide the Shared Drive for. + + Defaults to the AdminEmail user. + + .EXAMPLE + Hide-GSDrive -DriveId $driveIds + + Hides the specified DriveIds for the AdminEmail user + #> + [OutputType('Google.Apis.Drive.v3.Data.Drive')] + [cmdletbinding()] + Param + ( + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")] + [Alias('Id','TeamDriveId')] + [String[]] + $DriveId, + [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] + [Alias('Owner','PrimaryEmail','UserKey','Mail')] + [string] + $User = $Script:PSGSuite.AdminEmail + ) + Process { + if ($User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/drive' + ServiceType = 'Google.Apis.Drive.v3.DriveService' + User = $User + } + $service = New-GoogleService @serviceParams + foreach ($id in $DriveId) { + try { + $request = $service.Drives.Hide($id) + Write-Verbose "Hiding Shared Drive '$id' for user '$User'" + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } + } +} diff --git a/PSGSuite/Public/Drive/New-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/New-GSDrive.ps1 similarity index 67% rename from PSGSuite/Public/Drive/New-GSTeamDrive.ps1 rename to PSGSuite/Public/Drive/New-GSDrive.ps1 index d059806b..c13c748b 100644 --- a/PSGSuite/Public/Drive/New-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/New-GSDrive.ps1 @@ -1,68 +1,68 @@ -function New-GSTeamDrive { +function New-GSDrive { <# .SYNOPSIS - Creates a new Team Drive + Creates a new Shared Drive .DESCRIPTION - Creates a new Team Drive + Creates a new Shared Drive .PARAMETER Name - The name of the Team Drive + The name of the Shared Drive .PARAMETER User - The user to create the Team Drive for (must have permissions to create Team Drives) + The user to create the Shared Drive for (must have permissions to create Shared Drives) .PARAMETER RequestId - An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a Team Drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same Team Drive. If the Team Drive already exists a 409 error will be returned. + An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a Shared Drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same Shared Drive. If the Shared Drive already exists a 409 error will be returned. .PARAMETER CanAddChildren - Whether the current user can add children to folders in this Team Drive + Whether the current user can add children to folders in this Shared Drive - .PARAMETER CanChangeTeamDriveBackground - Whether the current user can change the background of this Team Drive + .PARAMETER CanChangeDriveBackground + Whether the current user can change the background of this Shared Drive .PARAMETER CanComment - Whether the current user can comment on files in this Team Drive + Whether the current user can comment on files in this Shared Drive .PARAMETER CanCopy - Whether the current user can copy files in this Team Drive + Whether the current user can copy files in this Shared Drive - .PARAMETER CanDeleteTeamDrive - Whether the current user can delete this Team Drive. Attempting to delete the Team Drive may still fail if there are untrashed items inside the Team Drive + .PARAMETER CanDeleteDrive + Whether the current user can delete this Shared Drive. Attempting to delete the Shared Drive may still fail if there are untrashed items inside the Shared Drive .PARAMETER CanDownload - Whether the current user can download files in this Team Drive + Whether the current user can download files in this Shared Drive .PARAMETER CanEdit - Whether the current user can edit files in this Team Drive + Whether the current user can edit files in this Shared Drive .PARAMETER CanListChildren - Whether the current user can list the children of folders in this Team Drive + Whether the current user can list the children of folders in this Shared Drive .PARAMETER CanManageMembers - Whether the current user can add members to this Team Drive or remove them or change their role + Whether the current user can add members to this Shared Drive or remove them or change their role .PARAMETER CanReadRevisions - Whether the current user can read the revisions resource of files in this Team Drive + Whether the current user can read the revisions resource of files in this Shared Drive .PARAMETER CanRemoveChildren - Whether the current user can remove children from folders in this Team Drive + Whether the current user can remove children from folders in this Shared Drive .PARAMETER CanRename - Whether the current user can rename files or folders in this Team Drive + Whether the current user can rename files or folders in this Shared Drive - .PARAMETER CanRenameTeamDrive - Whether the current user can rename this Team Drive + .PARAMETER CanRenameDrive + Whether the current user can rename this Shared Drive .PARAMETER CanShare - Whether the current user can share files or folders in this Team Drive + Whether the current user can share files or folders in this Shared Drive .EXAMPLE - New-GSTeamDrive -Name "Training Docs" + New-GSDrive -Name "Training Docs" - Creates a new Team Drive named "Training Docs" + Creates a new Shared Drive named "Training Docs" #> - [OutputType('Google.Apis.Drive.v3.Data.TeamDrive')] + [OutputType('Google.Apis.Drive.v3.Data.Drive')] [cmdletbinding()] Param ( @@ -81,8 +81,9 @@ function New-GSTeamDrive { [Switch] $CanAddChildren, [parameter(Mandatory = $false)] + [Alias('CanChangeTeamDriveBackground')] [Switch] - $CanChangeTeamDriveBackground, + $CanChangeDriveBackground, [parameter(Mandatory = $false)] [Switch] $CanComment, @@ -90,8 +91,9 @@ function New-GSTeamDrive { [Switch] $CanCopy, [parameter(Mandatory = $false)] + [Alias('CanDeleteTeamDrive')] [Switch] - $CanDeleteTeamDrive, + $CanDeleteDrive, [parameter(Mandatory = $false)] [Switch] $CanDownload, @@ -114,8 +116,9 @@ function New-GSTeamDrive { [Switch] $CanRename, [parameter(Mandatory = $false)] + [Alias('CanRenameTeamDrive')] [Switch] - $CanRenameTeamDrive, + $CanRenameDrive, [parameter(Mandatory = $false)] [Switch] $CanShare @@ -134,8 +137,8 @@ function New-GSTeamDrive { } $service = New-GoogleService @serviceParams try { - $body = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive' - $capabilities = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive+CapabilitiesData' + $body = New-Object 'Google.Apis.Drive.v3.Data.Drive' + $capabilities = New-Object 'Google.Apis.Drive.v3.Data.Drive+CapabilitiesData' foreach ($key in $PSBoundParameters.Keys) { switch ($key) { Default { @@ -149,8 +152,8 @@ function New-GSTeamDrive { } } $body.Capabilities = $capabilities - $request = $service.Teamdrives.Create($body,$RequestId) - Write-Verbose "Creating Team Drive '$Name' for user '$User'" + $request = $service.Drives.Create($body,$RequestId) + Write-Verbose "Creating Shared Drive '$Name' for user '$User'" $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'RequestId' -Value $RequestId -PassThru } catch { diff --git a/PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/Remove-GSDrive.ps1 similarity index 65% rename from PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 rename to PSGSuite/Public/Drive/Remove-GSDrive.ps1 index f99355b3..29e2a890 100644 --- a/PSGSuite/Public/Drive/Remove-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/Remove-GSDrive.ps1 @@ -1,31 +1,31 @@ -function Remove-GSTeamDrive { +function Remove-GSDrive { <# .SYNOPSIS - Removes a Team Drive + Removes a Shared Drive .DESCRIPTION - Removes a Team Drive + Removes a Shared Drive - .PARAMETER TeamDriveId - The Id of the Team Drive to remove + .PARAMETER DriveId + The Id of the Shared Drive to remove .PARAMETER User - The email or unique Id of the user with permission to delete the Team Drive + The email or unique Id of the user with permission to delete the Shared Drive Defaults to the AdminEmail user .EXAMPLE - Remove-TeamDrive -TeamDriveId "0AJ8Xjq3FcdCKUk9PVA" -Confirm:$false + Remove-Drive -DriveId "0AJ8Xjq3FcdCKUk9PVA" -Confirm:$false - Removes the Team Drive '0AJ8Xjq3FcdCKUk9PVA', skipping confirmation + Removes the Shared Drive '0AJ8Xjq3FcdCKUk9PVA', skipping confirmation #> [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")] Param ( [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] - [Alias('Id')] + [Alias('Id','TeamDriveId')] [String[]] - $TeamDriveId, + $DriveId, [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] [Alias('Owner','PrimaryEmail','UserKey','Mail')] [string] @@ -45,12 +45,12 @@ function Remove-GSTeamDrive { } $service = New-GoogleService @serviceParams try { - foreach ($id in $TeamDriveId) { - if ($PSCmdlet.ShouldProcess("Deleting Team Drive '$id' from user '$User'")) { - Write-Verbose "Deleting Team Drive '$id' from user '$User'" - $request = $service.Teamdrives.Delete($id) + foreach ($id in $DriveId) { + if ($PSCmdlet.ShouldProcess("Deleting Shared Drive '$id' from user '$User'")) { + Write-Verbose "Deleting Shared Drive '$id' from user '$User'" + $request = $service.Drives.Delete($id) $request.Execute() - Write-Verbose "Team Drive '$id' successfully deleted from user '$User'" + Write-Verbose "Shared Drive '$id' successfully deleted from user '$User'" } } } diff --git a/PSGSuite/Public/Drive/Show-GSDrive.ps1 b/PSGSuite/Public/Drive/Show-GSDrive.ps1 new file mode 100644 index 00000000..901d3051 --- /dev/null +++ b/PSGSuite/Public/Drive/Show-GSDrive.ps1 @@ -0,0 +1,64 @@ +function Show-GSDrive { + <# + .SYNOPSIS + Shows (unhides) a Shared Drive in the default view + + .DESCRIPTION + Shows (unhides) a Shared Drive in the default view + + .PARAMETER DriveId + The unique Id of the Shared Drive to unhide + + .PARAMETER User + The email or unique Id of the user who you'd like to unhide the Shared Drive for. + + Defaults to the AdminEmail user. + + .EXAMPLE + Show-GSDrive -DriveId $driveIds + + Unhides the specified DriveIds for the AdminEmail user + #> + [OutputType('Google.Apis.Drive.v3.Data.Drive')] + [cmdletbinding()] + Param + ( + [parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")] + [Alias('Id','TeamDriveId')] + [String[]] + $DriveId, + [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] + [Alias('Owner','PrimaryEmail','UserKey','Mail')] + [string] + $User = $Script:PSGSuite.AdminEmail + ) + Process { + if ($User -ceq 'me') { + $User = $Script:PSGSuite.AdminEmail + } + elseif ($User -notlike "*@*.*") { + $User = "$($User)@$($Script:PSGSuite.Domain)" + } + $serviceParams = @{ + Scope = 'https://www.googleapis.com/auth/drive' + ServiceType = 'Google.Apis.Drive.v3.DriveService' + User = $User + } + $service = New-GoogleService @serviceParams + foreach ($id in $DriveId) { + try { + $request = $service.Drives.Unhide($id) + Write-Verbose "Unhiding Shared Drive '$id' for user '$User'" + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } + } +} diff --git a/PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 b/PSGSuite/Public/Drive/Update-GSDrive.ps1 similarity index 66% rename from PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 rename to PSGSuite/Public/Drive/Update-GSDrive.ps1 index c6f3167c..a09b6f15 100644 --- a/PSGSuite/Public/Drive/Update-GSTeamDrive.ps1 +++ b/PSGSuite/Public/Drive/Update-GSDrive.ps1 @@ -1,74 +1,75 @@ -function Update-GSTeamDrive { +function Update-GSDrive { <# .SYNOPSIS - Update metatdata for a Team Drive + Update metatdata for a Shared Drive .DESCRIPTION - Update metatdata for a Team Drive + Update metatdata for a Shared Drive - .PARAMETER TeamDriveId - The unique Id of the Team Drive to update + .PARAMETER DriveId + The unique Id of the Shared Drive to update .PARAMETER User - The user to create the Team Drive for (must have permissions to create Team Drives) + The user to create the Shared Drive for (must have permissions to create Shared Drives) .PARAMETER Name - The name of the Team Drive + The name of the Shared Drive .PARAMETER CanAddChildren - Whether the current user can add children to folders in this Team Drive + Whether the current user can add children to folders in this Shared Drive - .PARAMETER CanChangeTeamDriveBackground - Whether the current user can change the background of this Team Drive + .PARAMETER CanChangeDriveBackground + Whether the current user can change the background of this Shared Drive .PARAMETER CanComment - Whether the current user can comment on files in this Team Drive + Whether the current user can comment on files in this Shared Drive .PARAMETER CanCopy - Whether the current user can copy files in this Team Drive + Whether the current user can copy files in this Shared Drive - .PARAMETER CanDeleteTeamDrive - Whether the current user can delete this Team Drive. Attempting to delete the Team Drive may still fail if there are untrashed items inside the Team Drive + .PARAMETER CanDeleteDrive + Whether the current user can delete this Shared Drive. Attempting to delete the Shared Drive may still fail if there are untrashed items inside the Shared Drive .PARAMETER CanDownload - Whether the current user can download files in this Team Drive + Whether the current user can download files in this Shared Drive .PARAMETER CanEdit - Whether the current user can edit files in this Team Drive + Whether the current user can edit files in this Shared Drive .PARAMETER CanListChildren - Whether the current user can list the children of folders in this Team Drive + Whether the current user can list the children of folders in this Shared Drive .PARAMETER CanManageMembers - Whether the current user can add members to this Team Drive or remove them or change their role + Whether the current user can add members to this Shared Drive or remove them or change their role .PARAMETER CanReadRevisions - Whether the current user can read the revisions resource of files in this Team Drive + Whether the current user can read the revisions resource of files in this Shared Drive .PARAMETER CanRemoveChildren - Whether the current user can remove children from folders in this Team Drive + Whether the current user can remove children from folders in this Shared Drive .PARAMETER CanRename - Whether the current user can rename files or folders in this Team Drive + Whether the current user can rename files or folders in this Shared Drive - .PARAMETER CanRenameTeamDrive - Whether the current user can rename this Team Drive + .PARAMETER CanRenameDrive + Whether the current user can rename this Shared Drive .PARAMETER CanShare - Whether the current user can share files or folders in this Team Drive + Whether the current user can share files or folders in this Shared Drive .EXAMPLE - Update-GSTeamDrive -TeamDriveId '0AJ8Xjq3FcdCKUk9PVA' -Name "HR Document Repo" + Update-GSDrive -DriveId '0AJ8Xjq3FcdCKUk9PVA' -Name "HR Document Repo" - Updated the Team Drive with a new name, "HR Document Repo" + Updated the Shared Drive with a new name, "HR Document Repo" #> - [OutputType('Google.Apis.Drive.v3.Data.TeamDrive')] + [OutputType('Google.Apis.Drive.v3.Data.Drive')] [cmdletbinding()] Param ( [parameter(Mandatory = $true,Position = 0)] + [Alias('Id','TeamDriveId')] [String] - $TeamDriveId, + $DriveId, [parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] [Alias('Owner','PrimaryEmail','UserKey','Mail')] [string] @@ -80,8 +81,9 @@ function Update-GSTeamDrive { [Switch] $CanAddChildren, [parameter(Mandatory = $false)] + [Alias('CanChangeTeamDriveBackground')] [Switch] - $CanChangeTeamDriveBackground, + $CanChangeDriveBackground, [parameter(Mandatory = $false)] [Switch] $CanComment, @@ -89,8 +91,9 @@ function Update-GSTeamDrive { [Switch] $CanCopy, [parameter(Mandatory = $false)] + [Alias('CanDeleteTeamDrive')] [Switch] - $CanDeleteTeamDrive, + $CanDeleteDrive, [parameter(Mandatory = $false)] [Switch] $CanDownload, @@ -113,8 +116,9 @@ function Update-GSTeamDrive { [Switch] $CanRename, [parameter(Mandatory = $false)] + [Alias('CanRenameTeamDrive')] [Switch] - $CanRenameTeamDrive, + $CanRenameDrive, [parameter(Mandatory = $false)] [Switch] $CanShare @@ -133,8 +137,8 @@ function Update-GSTeamDrive { } $service = New-GoogleService @serviceParams try { - $body = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive' - $capabilities = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive+CapabilitiesData' + $body = New-Object 'Google.Apis.Drive.v3.Data.Drive' + $capabilities = New-Object 'Google.Apis.Drive.v3.Data.Drive+CapabilitiesData' foreach ($key in $PSBoundParameters.Keys) { switch ($key) { Default { @@ -148,8 +152,8 @@ function Update-GSTeamDrive { } } $body.Capabilities = $capabilities - $request = $service.Teamdrives.Update($body,$TeamDriveId) - Write-Verbose "Updating Team Drive '$Name' for user '$User'" + $request = $service.Drives.Update($body,$DriveId) + Write-Verbose "Updating Shared Drive '$Name' for user '$User'" $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru } catch {