Public/Drive/Copy-GSDriveFile.ps1
function Copy-GSDriveFile { <# .SYNOPSIS Make a copy of a file in Drive .DESCRIPTION Make a copy of a file in Drive .PARAMETER FileID The unique Id of the file to copy .PARAMETER User The email or unique Id of the owner of the Drive file Defaults to the AdminEmail user .PARAMETER Name The name of the new Drive file copy .PARAMETER Description The description of the new Drive file copy .PARAMETER Parents The parent Ids of the new Drive file copy .PARAMETER Projection The defined subset of fields to be returned Available values are: * "Minimal" * "Standard" * "Full" * "Access" .PARAMETER Fields The specific fields to returned .EXAMPLE Copy-GSDriveFile -FileId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' -Name "New Daily Checklist" Copies the Drive file Id to a new Drive file named 'New Daily Checklist' #> [cmdletbinding(DefaultParameterSetName = "Depth")] Param ( [parameter(Mandatory = $true,Position = 0)] [String] $FileID, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [Alias('Owner','PrimaryEmail','UserKey','Mail')] [string] $User = $Script:PSGSuite.AdminEmail, [parameter(Mandatory = $false)] [String] $Name, [parameter(Mandatory = $false)] [String] $Description, [parameter(Mandatory = $false)] [String[]] $Parents, [parameter(Mandatory = $false,ParameterSetName = "Depth")] [Alias('Depth')] [ValidateSet("Minimal","Standard","Full","Access")] [String] $Projection = "Full", [parameter(Mandatory = $false,ParameterSetName = "Fields")] [ValidateSet("appProperties","capabilities","contentHints","createdTime","description","explicitlyTrashed","fileExtension","folderColorRgb","fullFileExtension","hasThumbnail","headRevisionId","iconLink","id","imageMediaMetadata","isAppAuthorized","kind","lastModifyingUser","md5Checksum","mimeType","modifiedByMe","modifiedByMeTime","modifiedTime","name","originalFilename","ownedByMe","owners","parents","permissions","properties","quotaBytesUsed","shared","sharedWithMeTime","sharingUser","size","spaces","starred","thumbnailLink","thumbnailVersion","trashed","version","videoMediaMetadata","viewedByMe","viewedByMeTime","viewersCanCopyContent","webContentLink","webViewLink","writersCanShare")] [String[]] $Fields ) Begin { if ($Projection) { $fs = switch ($Projection) { Standard { @("createdTime","description","fileExtension","id","lastModifyingUser","modifiedTime","name","owners","parents","properties","version","webContentLink","webViewLink") } Access { @("createdTime","description","fileExtension","id","lastModifyingUser","modifiedTime","name","ownedByMe","owners","parents","permissionIds","permissions","shared","sharedWithMeTime","sharingUser","viewedByMe","viewedByMeTime","viewersCanCopyContent","writersCanShare") } Full { @("appProperties","capabilities","contentHints","createdTime","description","explicitlyTrashed","fileExtension","folderColorRgb","fullFileExtension","hasAugmentedPermissions","hasThumbnail","headRevisionId","iconLink","id","imageMediaMetadata","isAppAuthorized","kind","lastModifyingUser","md5Checksum","mimeType","modifiedByMe","modifiedByMeTime","modifiedTime","name","originalFilename","ownedByMe","owners","parents","permissionIds","permissions","properties","quotaBytesUsed","shared","sharedWithMeTime","sharingUser","size","spaces","starred","teamDriveId","thumbnailLink","thumbnailVersion","trashed","trashedTime","trashingUser","version","videoMediaMetadata","viewedByMe","viewedByMeTime","viewersCanCopyContent","webContentLink","webViewLink","writersCanShare") } } } elseif ($Fields) { $fs = $Fields } 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 } Process { try { $body = New-Object 'Google.Apis.Drive.v3.Data.File' if ($Name) { $body.Name = $Name } if ($Description) { $body.Description = $Description } if ($Parents) { $body.Parents = [String[]]$Parents } $request = $service.Files.Copy($body,$FileID) $request.SupportsTeamDrives = $true if ($fs) { $request.Fields = "$($fs -join ",")" } Write-Verbose "Copying drive file id '$FileID'" $request.Execute() | Select-Object @{N = "User";E = {$User}},* } catch { if ($ErrorActionPreference -eq 'Stop') { $PSCmdlet.ThrowTerminatingError($_) } else { Write-Error $_ } } } } |