diff --git a/GMGoogleDrive/Public/Add-GDriveItemPermission.ps1 b/GMGoogleDrive/Public/Add-GDriveItemPermission.ps1 index 34f8134..c1ad289 100644 --- a/GMGoogleDrive/Public/Add-GDriveItemPermission.ps1 +++ b/GMGoogleDrive/Public/Add-GDriveItemPermission.ps1 @@ -88,7 +88,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Params = New-Object System.Collections.ArrayList # Always return all properties. @@ -102,6 +101,7 @@ param( } } $Uri = '{0}{1}/permissions?supportsAllDrives=true&{2}' -f $GDriveUri, $ID, ($Params -join '&') + Write-Verbose "URI: $Uri" $Body = @{ role = $Role type = $Type @@ -121,6 +121,11 @@ param( } $JsonProperty = ConvertTo-Json $Body Write-Verbose "RequestBody: $JsonProperty" - Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers @GDriveProxySettings -Body $JsonProperty + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Post -Body $JsonProperty @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/Clear-GDriveTrash.ps1 b/GMGoogleDrive/Public/Clear-GDriveTrash.ps1 index 2b22090..be33cfc 100644 --- a/GMGoogleDrive/Public/Clear-GDriveTrash.ps1 +++ b/GMGoogleDrive/Public/Clear-GDriveTrash.ps1 @@ -22,7 +22,11 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } - Invoke-RestMethod -Uri $GDriveTrashUri -Method Delete -Headers $Headers @GDriveProxySettings + $requestParams = @{ + Uri = $GDriveTrashUri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Delete @GDriveProxySettings } diff --git a/GMGoogleDrive/Public/Copy-GDriveItem.ps1 b/GMGoogleDrive/Public/Copy-GDriveItem.ps1 index ad43762..bb085fe 100644 --- a/GMGoogleDrive/Public/Copy-GDriveItem.ps1 +++ b/GMGoogleDrive/Public/Copy-GDriveItem.ps1 @@ -53,7 +53,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } # Full property set will be supported after the rain on Thursday ;-) @@ -70,6 +69,11 @@ param( Write-Verbose "Copy URI: $Uri" Write-Verbose "Copy Metadata: $JsonProperty" if ($PSCmdlet.ShouldProcess("Copy item $ID")) { - Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $JsonProperty @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Post -Body $JsonProperty @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/Find-GDriveItem.ps1 b/GMGoogleDrive/Public/Find-GDriveItem.ps1 index 5a86566..4d620eb 100644 --- a/GMGoogleDrive/Public/Find-GDriveItem.ps1 +++ b/GMGoogleDrive/Public/Find-GDriveItem.ps1 @@ -58,7 +58,6 @@ param( $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } Write-Verbose "URI: $GDriveUri" $Params = New-Object System.Collections.ArrayList @@ -91,6 +90,12 @@ param( } else { $Uri = '{0}?supportsAllDrives=true&{1}' -f $GDriveUri, ($Params -join '&') - Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings + Write-Verbose "URI: $Uri" + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/Get-GDriveError.ps1 b/GMGoogleDrive/Public/Get-GDriveError.ps1 index 8f2b011..ddbcc26 100644 --- a/GMGoogleDrive/Public/Get-GDriveError.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveError.ps1 @@ -3,7 +3,7 @@ Get GoogleDrive Error responce .DESCRIPTION Get GoogleDrive Error responce -.PARAMETER Error +.PARAMETER ErrorRecord Error record to decode .PARAMETER Exception Exception object to decode @@ -20,7 +20,7 @@ function Get-GDriveError { [CmdletBinding(DefaultParameterSetName='ex')] param( [Parameter(Mandatory, Position=0, ParameterSetName='er')] - [System.Management.Automation.ErrorRecord]$Error, + [System.Management.Automation.ErrorRecord]$ErrorRecord, [Parameter(Mandatory, Position=0, ParameterSetName='ex')] [Exception]$Exception @@ -31,8 +31,8 @@ param( Message = '' Error = '' } - if ($Error) { - $Exception = $Error.Exception + if ($ErrorRecord) { + $Exception = $ErrorRecord.Exception } if ($Exception) { $result.Type = $Exception.GetType() diff --git a/GMGoogleDrive/Public/Get-GDriveItemContent.ps1 b/GMGoogleDrive/Public/Get-GDriveItemContent.ps1 index 5f5eda5..0a20cbd 100644 --- a/GMGoogleDrive/Public/Get-GDriveItemContent.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveItemContent.ps1 @@ -93,7 +93,7 @@ param( } $wr.Method = 'Get' - $wr.ContentType = "application/json" + $wr.ContentType = "application/json; charset=utf-8" $wr.Headers.Add("Authorization", "Bearer $($AccessToken)") Write-Verbose "ParameterSetName: $($PSCmdlet.ParameterSetName)" Write-Verbose "Content Url: $Uri" diff --git a/GMGoogleDrive/Public/Get-GDriveItemPermission.ps1 b/GMGoogleDrive/Public/Get-GDriveItemPermission.ps1 index 48560d2..2a1e162 100644 --- a/GMGoogleDrive/Public/Get-GDriveItemPermission.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveItemPermission.ps1 @@ -43,7 +43,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Params = New-Object System.Collections.ArrayList # Always return all properties. @@ -52,5 +51,11 @@ param( [void]$Params.Add('useDomainAdminAccess=true') } $Uri = '{0}{1}/permissions/{2}?supportsAllDrives=true&{3}' -f $GDriveUri, $ID, $PermissionID, ($Params -join '&') - Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings + Write-Verbose "URI: $Uri" + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings } diff --git a/GMGoogleDrive/Public/Get-GDriveItemPermissionList.ps1 b/GMGoogleDrive/Public/Get-GDriveItemPermissionList.ps1 index a045ae0..0f17aa5 100644 --- a/GMGoogleDrive/Public/Get-GDriveItemPermissionList.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveItemPermissionList.ps1 @@ -54,7 +54,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } if ($AllResults) { [void]$PSBoundParameters.Remove('AllResults') @@ -85,6 +84,12 @@ param( [void]$Params.Add('pageToken=' + $NextPageToken) } $Uri = '{0}{1}/permissions/?supportsAllDrives=true&{2}' -f $GDriveUri, $ID, ($Params -join '&') - Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings + Write-Verbose "URI: $Uri" + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/Get-GDriveItemProperty.ps1 b/GMGoogleDrive/Public/Get-GDriveItemProperty.ps1 index a53db53..49d56c9 100644 --- a/GMGoogleDrive/Public/Get-GDriveItemProperty.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveItemProperty.ps1 @@ -53,7 +53,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Revision = if ($RevisionID) { '/revisions/' + $RevisionID } else { '' } if ($Property -contains "*") { @@ -64,6 +63,10 @@ param( $Uri += '&fields={0}' -f ($Property -join ',') } Write-Verbose "URI: $Uri" - - Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings } diff --git a/GMGoogleDrive/Public/Get-GDriveItemRevisionList.ps1 b/GMGoogleDrive/Public/Get-GDriveItemRevisionList.ps1 index 3a40fc0..7451ee6 100644 --- a/GMGoogleDrive/Public/Get-GDriveItemRevisionList.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveItemRevisionList.ps1 @@ -46,7 +46,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } if ($AllResults) { [void]$PSBoundParameters.Remove('AllResults') @@ -74,6 +73,12 @@ param( [void]$Params.Add('pageToken=' + $NextPageToken) } $Uri = '{0}{1}/revisions/?supportsAllDrives=true&{2}' -f $GDriveUri, $ID, ($Params -join '&') - Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers @GDriveProxySettings + Write-Verbose "URI: $Uri" + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/Get-GDriveSummary.ps1 b/GMGoogleDrive/Public/Get-GDriveSummary.ps1 index e579388..aa9bf22 100644 --- a/GMGoogleDrive/Public/Get-GDriveSummary.ps1 +++ b/GMGoogleDrive/Public/Get-GDriveSummary.ps1 @@ -23,8 +23,11 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } - - Invoke-RestMethod -Uri $GDriveAboutURI -Method Get -Headers $Headers @GDriveProxySettings + $requestParams = @{ + Uri = $GDriveAboutURI + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Get @GDriveProxySettings } diff --git a/GMGoogleDrive/Public/Move-GDriveItem.ps1 b/GMGoogleDrive/Public/Move-GDriveItem.ps1 index 6de0be9..dafa83a 100644 --- a/GMGoogleDrive/Public/Move-GDriveItem.ps1 +++ b/GMGoogleDrive/Public/Move-GDriveItem.ps1 @@ -57,9 +57,13 @@ param( $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } if ($PSCmdlet.ShouldProcess("Move item $ID to $($NewParentID -join ',')")) { - Invoke-RestMethod -Uri $Uri -Method Patch -Headers $Headers @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Patch @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/New-GDriveFolder.ps1 b/GMGoogleDrive/Public/New-GDriveFolder.ps1 index 6ac1f8d..c51585a 100644 --- a/GMGoogleDrive/Public/New-GDriveFolder.ps1 +++ b/GMGoogleDrive/Public/New-GDriveFolder.ps1 @@ -35,13 +35,17 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Uri = $GDriveUri + '?supportsAllDrives=true' Write-Verbose "URI: $Uri" $RequestBody = '{{ "name": "{0}", "mimeType": "application/vnd.google-apps.folder", "parents": ["{1}"] }}' -f $Name, ($ParentID -join '","') Write-Verbose "RequestBody: $RequestBody" if ($PSCmdlet.ShouldProcess("Create new folder $Name")) { - Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $RequestBody @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Post -Body $RequestBody @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/New-GDriveItem.ps1 b/GMGoogleDrive/Public/New-GDriveItem.ps1 index 74731c3..2f6fb45 100644 --- a/GMGoogleDrive/Public/New-GDriveItem.ps1 +++ b/GMGoogleDrive/Public/New-GDriveItem.ps1 @@ -52,7 +52,6 @@ function New-GDriveItem { $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } # Full property set will be supported after the rain on Thursday ;-) $Property = 'kind','id','name','mimeType','parents' @@ -60,6 +59,11 @@ function New-GDriveItem { Write-Verbose "URI: $Uri" Write-Verbose "RequestBody: $JsonProperty" if ($PSCmdlet.ShouldProcess("Create new item $Name")) { - Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $JsonProperty @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Post -Body $JsonProperty @GDriveProxySettings } } diff --git a/GMGoogleDrive/Public/Remove-GDriveItem.ps1 b/GMGoogleDrive/Public/Remove-GDriveItem.ps1 index c57c44e..191bd05 100644 --- a/GMGoogleDrive/Public/Remove-GDriveItem.ps1 +++ b/GMGoogleDrive/Public/Remove-GDriveItem.ps1 @@ -48,14 +48,18 @@ param( if ($Permanently -or $RevisionID) { $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Revision = if ($RevisionID) { '/revisions/' + $RevisionID } else { '' } $Uri = '{0}{1}{2}?{3}' -f $GDriveUri, $ID, $Revision, "?supportsAllDrives=true" Write-Verbose "URI: $Uri" if ($PSCmdlet.ShouldProcess("Remove Item $ID")) { - Invoke-RestMethod -Uri $Uri -Method Delete -Headers $Headers @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Delete @GDriveProxySettings } } else { diff --git a/GMGoogleDrive/Public/Remove-GDriveItemPermission.ps1 b/GMGoogleDrive/Public/Remove-GDriveItemPermission.ps1 index 6c0e353..716a60d 100644 --- a/GMGoogleDrive/Public/Remove-GDriveItemPermission.ps1 +++ b/GMGoogleDrive/Public/Remove-GDriveItemPermission.ps1 @@ -42,7 +42,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Params = New-Object System.Collections.ArrayList # Always return all properties. @@ -51,5 +50,11 @@ param( [void]$Params.Add('useDomainAdminAccess=true') } $Uri = '{0}{1}/permissions/{2}?supportsAllDrives=true&{3}' -f $GDriveUri, $ID, $PermissionID, ($Params -join '&') - Invoke-RestMethod -Uri $Uri -Method Delete -Headers $Headers @GDriveProxySettings + Write-Verbose "URI: $Uri" + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Delete @GDriveProxySettings } diff --git a/GMGoogleDrive/Public/Set-GDriveItemContent.ps1 b/GMGoogleDrive/Public/Set-GDriveItemContent.ps1 index 6ec3e1a..123f49e 100644 --- a/GMGoogleDrive/Public/Set-GDriveItemContent.ps1 +++ b/GMGoogleDrive/Public/Set-GDriveItemContent.ps1 @@ -152,13 +152,13 @@ function Set-GDriveItemContent { try { $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" "X-Upload-Content-Type" = $ContentType "X-Upload-Content-Length" = $stream.Length } $WebRequestParams = @{ Headers = $Headers + ContentType = "application/json; charset=utf-8" MaximumRedirection = 0 UseBasicParsing = $true Body = $JsonProperty diff --git a/GMGoogleDrive/Public/Set-GDriveItemPermission.ps1 b/GMGoogleDrive/Public/Set-GDriveItemPermission.ps1 index 852f5a7..16730b8 100644 --- a/GMGoogleDrive/Public/Set-GDriveItemPermission.ps1 +++ b/GMGoogleDrive/Public/Set-GDriveItemPermission.ps1 @@ -65,7 +65,6 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Params = New-Object System.Collections.ArrayList # Always return all properties. @@ -76,6 +75,7 @@ param( } } $Uri = '{0}{1}/permissions/{2}?supportsAllDrives=true&{3}' -f $GDriveUri, $ID, $PermissionID, ($Params -join '&') + Write-Verbose "URI: $Uri" $Body = @{ role = $Role } @@ -84,5 +84,10 @@ param( } $JsonProperty = ConvertTo-Json $Body Write-Verbose "RequestBody: $JsonProperty" - Invoke-RestMethod -Uri $Uri -Method Patch -Headers $Headers @GDriveProxySettings -Body $JsonProperty + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Patch -Body $JsonProperty @GDriveProxySettings } diff --git a/GMGoogleDrive/Public/Set-GDriveItemProperty.ps1 b/GMGoogleDrive/Public/Set-GDriveItemProperty.ps1 index fece2d4..016b176 100644 --- a/GMGoogleDrive/Public/Set-GDriveItemProperty.ps1 +++ b/GMGoogleDrive/Public/Set-GDriveItemProperty.ps1 @@ -43,13 +43,17 @@ param( ) $Headers = @{ "Authorization" = "Bearer $AccessToken" - "Content-type" = "application/json" } $Revision = if ($RevisionID) { '/revisions/' + $RevisionID } else { '' } $Uri = '{0}{1}{2}?{3}' -f $GDriveUri, $ID, $Revision, "?supportsAllDrives=true" Write-Verbose "URI: $Uri" if ($PSCmdlet.ShouldProcess("Set property for item $ID")) { - Invoke-RestMethod -Uri $Uri -Method Patch -Headers $Headers -Body $JsonProperty @GDriveProxySettings + $requestParams = @{ + Uri = $Uri + Headers = $Headers + ContentType = "application/json; charset=utf-8" + } + Invoke-RestMethod @requestParams -Method Patch -Body $JsonProperty @GDriveProxySettings } }