diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1d2a5c..409b829b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,35 +3,40 @@ - [Changelog](#changelog) - - [2.6.2](#262) - - [2.6.1](#261) - - [2.6.0](#260) - - [2.5.4](#254) - - [2.5.3](#253) - - [2.5.2](#252) - - [2.5.1](#251) - - [2.5.0](#250) - - [2.4.0](#240) - - [2.3.0](#230) - - [2.2.1](#221) - - [2.2.0](#220) - - [2.1.5](#215) - - [2.1.3 / 2.1.4](#213---214) - - [2.1.2](#212) - - [2.1.1](#211) - - [2.1.0](#210) - - [2.0.3](#203) - - [2.0.2](#202) - - [2.0.1](#201) - - [2.0.0](#200) - - [New Functionality](#new-functionality) - - [Breaking Changes in 2.0.0](#breaking-changes-in-200) - - [Gmail Delegation Management Removed](#gmail-delegation-management-removed) - - [Functions Removed](#functions-removed) - - [Functions Aliased](#functions-aliased) + - [2.6.3](#263) + - [2.6.2](#262) + - [2.6.1](#261) + - [2.6.0](#260) + - [2.5.4](#254) + - [2.5.3](#253) + - [2.5.2](#252) + - [2.5.1](#251) + - [2.5.0](#250) + - [2.4.0](#240) + - [2.3.0](#230) + - [2.2.1](#221) + - [2.2.0](#220) + - [2.1.5](#215) + - [2.1.3 / 2.1.4](#213--214) + - [2.1.2](#212) + - [2.1.1](#211) + - [2.1.0](#210) + - [2.0.3](#203) + - [2.0.2](#202) + - [2.0.1](#201) + - [2.0.0](#200) + - [New Functionality](#new-functionality) + - [Breaking Changes in 2.0.0](#breaking-changes-in-200) + - [Gmail Delegation Management Removed](#gmail-delegation-management-removed) + - [Functions Removed](#functions-removed) + - [Functions Aliased](#functions-aliased) +## 2.6.3 + +* Fixed: `Export-GSDriveFile -OutFilePath C:\doc.pdf -Type PDF` failing due to incorrect parameter validation. ([Issue #51](https://github.com/scrthq/PSGSuite/issues/51)) + ## 2.6.2 * Added: `Get-GSGmailProfile` and `Get-GSDriveProfile` to pull down information for a user's Gmail or Drive account. diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index c89d634d..26247d38 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.6.2' + ModuleVersion = '2.6.3' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 b/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 index f2791933..e5063931 100644 --- a/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 +++ b/PSGSuite/Public/Drive/Export-GSDriveFile.ps1 @@ -55,7 +55,7 @@ function Export-GSDriveFile { Exports the Drive file as a CSV to the current working directory #> - [cmdletbinding(DefaultParameterSetName = "Depth")] + [CmdLetBinding(DefaultParameterSetName = "Depth")] Param ( [parameter(Mandatory = $true,Position = 0)] @@ -66,13 +66,12 @@ function Export-GSDriveFile { [string] $User = $Script:PSGSuite.AdminEmail, [parameter(Mandatory = $true)] - [ValidateSet("CSV","HTML","JPEG","JSON","MSExcel","MSPowerPoint","MSWordDoc","OpenOfficeDoc","OpenOfficeSheet","PDF","PlainText","PNG","RichText","SVG")] + [ValidateSet("CSV","EPUB","HTML","HTMLZipped","JPEG","JSON","MSExcel","MSPowerPoint","MSWordDoc","OpenOfficeDoc","OpenOfficePresentation","OpenOfficeSheet","PDF","PlainText","PNG","RichText","SVG","TSV")] [String] $Type, [parameter(Mandatory = $false)] - [ValidateScript({(Get-Item $_).PSIsContainer})] [String] - $OutFilePath = (Get-Location).Path, + $OutFilePath, [parameter(Mandatory = $false,ParameterSetName = "Depth")] [Alias('Depth')] [ValidateSet("Minimal","Standard","Full","Access")] @@ -81,7 +80,10 @@ function Export-GSDriveFile { [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 + $Fields, + [parameter(Mandatory = $false)] + [Switch] + $Force ) Begin { if ($Projection) { @@ -101,20 +103,24 @@ function Export-GSDriveFile { $fs = $Fields } $mimeHash = @{ - CSV = "text/csv" - HTML = "text/html" - JPEG = "image/jpeg" - JSON = "application/vnd.google-apps.script+json" - MSExcel = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" - MSPowerPoint = "application/vnd.openxmlformats-officedocument.presentationml.presentation" - MSWordDoc = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" - OpenOfficeDoc = "application/vnd.oasis.opendocument.text" - OpenOfficeSheet = "application/x-vnd.oasis.opendocument.spreadsheet" - PDF = "application/pdf" - PlainText = "text/plain" - PNG = "image/png" - RichText = "application/rtf" - SVG = "image/svg+xml" + CSV = "text/csv" + EPUB = "application/epub+zip" + HTML = "text/html" + HTMLZipped = "application/zip" + JPEG = "image/jpeg" + JSON = "application/vnd.google-apps.script+json" + MSExcel = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + MSPowerPoint = "application/vnd.openxmlformats-officedocument.presentationml.presentation" + MSWordDoc = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + OpenOfficeDoc = "application/vnd.oasis.opendocument.text" + OpenOfficePresentation = "application/vnd.oasis.opendocument.presentation" + OpenOfficeSheet = "application/x-vnd.oasis.opendocument.spreadsheet" + PDF = "application/pdf" + PlainText = "text/plain" + PNG = "image/png" + RichText = "application/rtf" + SVG = "image/svg+xml" + TSV = "text/tab-separated-values" } if ($User -ceq 'me') { $User = $Script:PSGSuite.AdminEmail @@ -135,14 +141,20 @@ function Export-GSDriveFile { if ($fs) { $request.Fields = $($fs -join ",") } - $res = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru if ($OutFilePath) { - Write-Verbose "Saving file to path '$OutFilePath'" - $stream = [System.IO.File]::Create($OutFilePath) - $request.Download($stream) - $stream.Close() + if ((Test-Path $OutFilePath) -and !$Force) { + throw "File '$OutFilePath' already exists. If you would like to overwrite it, use the -Force parameter." + } + else { + Write-Verbose "Saving file to path '$OutFilePath'" + $stream = [System.IO.File]::Create($OutFilePath) + $request.Download($stream) + $stream.Close() + } + } + else { + $request.Execute() } - $res } catch { if ($ErrorActionPreference -eq 'Stop') { diff --git a/README.md b/README.md index 1d4ecbf4..87125c58 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,10 @@ Update-GSSheetValue Export-GSSheet ### Most recent changes +#### 2.6.3 + +* Fixed: `Export-GSDriveFile -OutFilePath C:\doc.pdf -Type PDF` failing due to incorrect parameter validation. ([Issue #51](https://github.com/scrthq/PSGSuite/issues/51)) + #### 2.6.2 * Added: `Get-GSGmailProfile` and `Get-GSDriveProfile` to pull down information for a user's Gmail or Drive account.