SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
234 stars 67 forks source link

[Question] - Set-GSDocContent fails without setting $serviceParams first #316

Open liab25 opened 3 years ago

liab25 commented 3 years ago

Describe the bug Running $localFile | Set-GSDocContent -FileId 'fake_file_id' fails with

New-GoogleService : Cannot validate argument on parameter 'Scope'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At C:\Users\lia.cha\Documents\WindowsPowerShell\Modules\PSGSuite\2.36.4\PSGSuite.psm1:11889 char:38
$service = New-GoogleService @serviceParams
CategoryInfo          : InvalidData: (:) [New-GoogleService], ParameterBindingValidationException
FullyQualifiedErrorId : ParameterArgumentValidationError,New-GoogleService

Set-GSDocContent : You cannot call a method on a null-valued expression.
At line:1 char:14
localFile | Set-GSDocContent -FileID $gfile.id -User svc-gdriveupload ...
CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-GSDocContent

To Reproduce Steps to reproduce the behavior:

  1. Manually set the $serviceParam variable
  2. Re-run the command and no errors noticed

Not sure if it matters, but i only granted my service account access to the drive API because i only need to be able to read and write to specific shared drives.

Also after manually defining the $serviceParams variable, verbose output shows an attempt to update the contents with no errors however the file remains the same without the expected new text updates.

FISHMANPET commented 3 years ago

Pretty sure this is a bug, in Set-GSDocContent (and Add-GSDocContent) the $service object is constructed with $serviceParams in the Begin block but the $serviceParams variable isn't defined until the Process block.

However once I manually defined $serviceParams I was able to set and add content in a simple google doc, so that part appears to be functioning, are you sure you passed in content to add?

liab25 commented 3 years ago

@FISHMANPET - yeah i noticed that in those functions too. I was a bit confused but thought maybe i missed something there. As for the actual updating of the file, I was using the wrong function. The files I was testing against were .txt files not google docs. After going through the function documentation several times, i realized those are only for updating google docs. Once i swapped to the Update-GSDriveFile function, everything worked out great.

FISHMANPET commented 2 years ago

This has been fixed in https://github.com/SCRT-HQ/PSGSuite/commit/eaf4bf213c7a451c94983cba7c523833ac0d893a, which has also been merged into https://github.com/SCRT-HQ/PSGSuite/tree/release/2.37.0, so the fix should in theory be deployed when the 2.37.0 release is made.