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
235 stars 67 forks source link

Start-gsdrivefileupload recurse function doesn't place the files in the correct parent directory #235

Open TheEZ12c opened 4 years ago

TheEZ12c commented 4 years ago

Describe the bug When using the start-psdrivefileupload function with the recurse switch, it will create the folder structure of the directory to be uploaded, but then it places all of the files in the root directory.

To Reproduce Steps to reproduce the behavior:

  1. Use start-gsdrivefileUpload
  2. Use recurse switch

Expected behavior In the documentation it states that it should place the files in the same directory pattern in Google as the original directory

Environment (please complete the following information):

scrthq commented 4 years ago

👀 checking this out, thanks @TheEZ12c ! Just to confirm, you're not passing a value to the Parents parameter on Start-GSDriveFileUpload, right?

TheEZ12c commented 4 years ago

I do put in the parent Id for the folder I would like everything placed under.

On Wed, Sep 25, 2019, 11:08 AM Nate Ferrell notifications@github.com wrote:

👀 checking this out, thanks @TheEZ12c https://github.com/TheEZ12c ! Just to confirm, you're not passing a value to the Parents parameter on Start-GSDriveFileUpload, right?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scrthq/PSGSuite/issues/235?email_source=notifications&email_token=ANJXK3TMPFB7IPRU5ON3E4TQLOEHZA5CNFSM4I2OJSBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7SOQCQ#issuecomment-535095306, or mute the thread https://github.com/notifications/unsubscribe-auth/ANJXK3VUK26FGSN6KQLGYZ3QLOEHZANCNFSM4I2OJSBA .

scrthq commented 4 years ago

alright, seeing if I can replicate and will let you know! If you have a sample of the full command you're running with anything sensitive redacted, that would be helpful!

TheEZ12c commented 4 years ago

Sure thing! I was just testing it out and using it pretty straight forward.

Start-GSDriveFileUpload -path $MyPath -Name $File.name -Parents $Parent -user $User -recurse -wait

Just doing that one liner was causing the issue to crop up

On Wed, Sep 25, 2019 at 3:02 PM Nate Ferrell notifications@github.com wrote:

alright, seeing if I can replicate and will let you know! If you have a sample of the full command you're running with anything sensitive redacted, that would be helpful!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scrthq/PSGSuite/issues/235?email_source=notifications&email_token=ANJXK3RZTVCUTERAXUC5WGDQLO7VVA5CNFSM4I2OJSBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7TFJKY#issuecomment-535188651, or mute the thread https://github.com/notifications/unsubscribe-auth/ANJXK3V74X6OTHWVXH2D5VDQLO7VVANCNFSM4I2OJSBA .

scrthq commented 4 years ago

Hey @TheEZ12c - The only way I'm able to replicate this is if I pass a bad ParentId to the Parents parameter, at which point all of the subfolders are created directly under the root of the Drive.

How are you pulling the parent ID of the folder that you're trying to upload to?

The easiest way to get the folder ID of the parent folder is to open the folder in Drive, then grab the ID from the URL. Your URL should look something like this with the bold section highlighting the folder ID you would want to pass to the Parents parameter:

https://drive.google.com/drive/u/0/folders/ 1CyslrEPaPt3YPehPUFFNRmQOrPzrSQ_7

Your call to upload a recursive folder structure should look something like this:

Start-GSDriveFileUpload -Path .\PSGSuite\Public -Parents '1CyslrEPaPt3YPehPUFFNRmQOrPzrSQ_7' -Recurse -Wait -Verbose

If you enable Verbose, you should see something like the following:

image


Also FYI - I need to remove the Name parameter from the function as it currently doesn't do anything after reviewing the code and wouldn't make sense anyway when uploading a recursive folder/file structure, tbh.

TheEZ12c commented 4 years ago

Hey Nate, thinks for taking a look! It is a folder in a shared drive and I am getting the ID by get-gsdrivefilelist | where {$_.name -like "blah"}. Weird thing is is that it makes the folder structure in the correct spot, just doesnt put the files there.

On Sun, Oct 6, 2019, 3:15 AM Nate Ferrell notifications@github.com wrote:

Hey @TheEZ12c https://github.com/TheEZ12c - The only way I'm able to replicate this is if I pass a bad ParentId to the Parents parameter, at which point all of the subfolders are created directly under the root of the Drive.

How are you pulling the parent ID of the folder that you're trying to upload to?

The easiest way to get the folder ID of the parent folder is to open the folder in Drive, then grab the ID from the URL. Your URL should look something like this with the bold section highlighting the folder ID you would want to pass to the Parents parameter:

https://drive.google.com/drive/u/0/folders/ 1CyslrEPaPt3YPehPUFFNRmQOrPzrSQ_7

Your call to upload a recursive folder structure should look something like this:

Start-GSDriveFileUpload -Path .\PSGSuite\Public -Parents '1CyslrEPaPt3YPehPUFFNRmQOrPzrSQ_7' -Recurse -Wait -Verbose

If you enable Verbose, you should see something like the following:

[image: image] https://user-images.githubusercontent.com/12724445/66266193-3722cd00-e7e7-11e9-9e97-4117657e416c.png

Also FYI - I need to remove the Name parameter from the function as it currently doesn't do anything after reviewing the code and wouldn't make sense anyway when uploading a recursive folder/file structure, tbh.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scrthq/PSGSuite/issues/235?email_source=notifications&email_token=ANJXK3RB42FEX72YOA2R7ZDQNGNCPA5CNFSM4I2OJSBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAOEB7A#issuecomment-538722556, or mute the thread https://github.com/notifications/unsubscribe-auth/ANJXK3SCSNNJ3YO2SIC3IPLQNGNCPANCNFSM4I2OJSBA .

scrthq commented 4 years ago

Gotcha! That Shared Drive bit definitely helps! Let me test and see if I can replicate, could absolutely be a Shared Drive issue since the underlying Request objects for Drive SDK need to be flagged as supporting Shared Drives specifically. Digging in once more!

scrthq commented 4 years ago

Just to confirm @TheEZ12c - Do the files get uploaded to a Shared Drive folder, just not in the correct, new folder structure? or do the folders get created in the Shared Drive, but the files are uploaded to the root of My Drive?

scrthq commented 4 years ago

So the odd part for me is that it also appears to be working fine with a Shared Drive. Testing - PSGSuite is a Shared Drive which I pointed my test at as the Parent, path was set to the Public folder of the PSGSuite functions in this repo:

image

scrthq commented 4 years ago

Tried a subfolder in a Shared Drive as well, still working fine for me :-(

image

TheEZ12c commented 4 years ago

Huh, that's weird. For the shared drive it was creating the structure but putting the files in the root of the shared drive.

Which version are you testing with? I will also test again this morning when I get in the office.

On Sun, Oct 6, 2019, 11:51 PM Nate Ferrell notifications@github.com wrote:

Tried a subfolder in a Shared Drive as well, still working fine for me :-(

[image: image] https://user-images.githubusercontent.com/12724445/66285839-3300b900-e894-11e9-9567-267a1b1d09db.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scrthq/PSGSuite/issues/235?email_source=notifications&email_token=ANJXK3R4WYRWHRARJ6KPD2DQNK543A5CNFSM4I2OJSBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPAN2Y#issuecomment-538838763, or mute the thread https://github.com/notifications/unsubscribe-auth/ANJXK3W7AUBRJT36W627VI3QNK543ANCNFSM4I2OJSBA .

scrthq commented 4 years ago

Testing with the latest version (2.33.2), but there hasn't been any code changes to the logic that determines where to upload a file to in a while.

If you run with Verbose, that might illuminate some issues potentially. I'm assuming you're not seeing any errors either at any point?

TheEZ12c commented 4 years ago

Okay, so just uploaded to the shared drive and it worked... The only other difference that I can think is that some of the files that I was attempting to upload were from a network share. I didn't look through too terribly closely at the code to see if that might affect it. Would that be it?

For example, it would be like "start-gsdrivefileupload -path \server\share\folderinshare -parent TeamDriveID -recurse"

On Mon, Oct 7, 2019 at 11:33 AM Nate Ferrell notifications@github.com wrote:

Testing with the latest version (2.33.2), but there hasn't been any code changes to the logic that determines where to upload a file to in a while.

If you run with Verbose, that might illuminate some issues potentially. I'm assuming you're not seeing any errors either at any point?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scrthq/PSGSuite/issues/235?email_source=notifications&email_token=ANJXK3WNLP5IZR5ON57BKPTQNNQEZA5CNFSM4I2OJSBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAQ7TXY#issuecomment-539097567, or mute the thread https://github.com/notifications/unsubscribe-auth/ANJXK3T5QLPNXZOSDP3N3PDQNNQEZANCNFSM4I2OJSBA .

scrthq commented 4 years ago

hmmm I don't think it would, since it's only looking at the source folder itself, not the full path to it, when pulling that info... it may break it though... I can try and replicate from my end as well

scrthq commented 4 years ago

hey @TheEZ12c - still haven't had a chance to test this further with a UNC path, I'll let you know once I'm able to though!