Automation of everything
mvkozlov / gmgoogledrive Goto Github PK
View Code? Open in Web Editor NEWGoogle Drive REST Api module for Powershell
License: MIT License
Google Drive REST Api module for Powershell
License: MIT License
Automation of everything
Hello,
Thanks for the script.
I'm trying to create a script that would be configured as a daily windows scheduled task to check some dates of backup files that get uploaded to Google Drive.
I put together a script using the readme and it prompts to sign in to google and asks to allow the user to "view and manage the files in your google drive".
Could someone help me automate this part?
Thanks,
Zach
Hello,
I don't know if we can use your framework with Service account login file.
https://developers.google.com/identity/protocols/oauth2/service-account#python
Thx in advance.
I want this to create a folder then create the share of the folder to anyone who has a link.
Is this possible?
upload files to static link?
i need to upload the files in pc1 and download the files in pc2 but pc2 doesn't know the link
so can you make a static link? to upload files and download files
Receiving the following error when using the Set-GDriveItemContent
cmdlet when attempting to update an existing file, similarly getting the same error when using Add-GDriveItem
which uses it as well when attempting to create a new file.
PS C:\users\test\Desktop> echo $file.FullName
C:\users\test\Desktop\Documents\test.rtsz
PS C:\users\test\Desktop> echo $idValue
1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm
PS C:\users\test\Desktop> Set-GDriveItemContent -AccessToken $accessToken -InFile $file.FullName -ID $idValue -Verbose
VERBOSE: Updating File 1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm
VERBOSE: URI: https://www.googleapis.com/upload/drive/v3/files/1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm?supportsAllDrives=true&uploadType=r
esumable&fields=kind,id,name,mimeType,parents
VERBOSE: Metadata upload, resumable, 37193 bytes, application/octet-stream
VERBOSE: Performing the operation "Uploading file from [C:\users\test\Desktop\Documents\test.rtsz]" on target "1Q1v-SX
Vaz0s0v6UOmVqhEjcmnuj1gEJm".
VERBOSE: PATCH https://www.googleapis.com/upload/drive/v3/files/1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm?supportsAllDrives=true&uploadType=
resumable&fields=kind,id,name,mimeType,parents with -1-byte payload
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8,application/json; charset=UTF-8
Set-GDriveItemContent : System.ArgumentNullException: Value cannot be null.
Parameter name: name
at System.Globalization.EncodingTable.GetCodePageFromName(String name)
at System.Text.Encoding.GetEncoding(String name)
at Microsoft.PowerShell.Commands.ContentHelper.GetEncodingOrDefault(String characterSet)
at Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject.InitializeContent()
at Microsoft.PowerShell.Commands.WebResponseObjectFactory.GetResponseObject(WebResponse response, Stream responseStream,
ExecutionContext executionContext, Boolean useBasicParsing)
at Microsoft.PowerShell.Commands.InvokeWebRequestCommand.ProcessResponse(WebResponse response)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
At line:1 char:1
+ Set-GDriveItemContent -AccessToken $accessToken -InFile $file.FullNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-GDriveItemContent
Uploading a file pf3910287872.tmp with 5144978 bytes results in an endless loop.
Inspecting the code of I see 2 times: $UploadedSize = ([long]$matches[2]) + 1
Could it be that $matches is missing in the code?
VERBOSE: URI: https://www.googleapis.com/drive/v3/files/
VERBOSE: URI: https://www.googleapis.com/drive/v3/files/?supportsAllDrives=true&pageSize=100&q=name
VERBOSE: URI: https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=r
VERBOSE: Metadata upload, resumable, 5144978 bytes, application/octet-stream
VERBOSE: Performing the operation "Uploading file named 'pf3910287872.tmp' from [d:\Temp\pf39102878
VERBOSE: POST https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=r
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: ResumeID: ADPycdsBKYRQlfKVLLT2N-eS-Oe-Gpka8--qkjaPZgRpJm2Q-au7T6hHj2mssnH2X4KpPrxADwypmxbC
VERBOSE: Received Range:
VERBOSE: Performing the operation "Uploading file named 'pf3910287872.tmp' from [d:\Temp\pf39102878
VERBOSE: Multiple requests upload
VERBOSE: Content-Length: 4194304, Content-Range bytes 0-4194303/5144978, readed: 4194304
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 4194304, UploadedSize:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 5144978, UploadedSize:4194304
VERBOSE: Fast Forward to:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 5144978, UploadedSize:4194304
VERBOSE: Fast Forward to:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 5144978, UploadedSize:4194304
VERBOSE: Fast Forward to:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
etc. etc
Good time of day!
First of all, sorry for my english.
When I upload / create an item on GDrive from a source file / directory with a name containing Cyrillic characters, the target item name on GDrive contains unreadable characters.
My environment
Windows 8.1/10 PRO RU
$PSVersionTable:
Name Value
---- -----
PSVersion 5.1.17763.1490
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1490
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
$OutputEncoding
IsSingleByte : True
BodyName : koi8-r
EncodingName : Кириллица (Windows)
HeaderName : windows-1251
WebName : windows-1251
WindowsCodePage : 1251
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : True
IsMailNewsSave : True
EncoderFallback : System.Text.InternalEncoderBestFitFallback
DecoderFallback : System.Text.InternalDecoderBestFitFallback
IsReadOnly : True
CodePage : 1251
Sorry for the stupid question, I just started learning powershell right now.
I've read the README file but haven't found how to import it into my scripts.
How can I do that?
Select-Object : Property "forms" cannot be found.
At C:\Development Tools\GMGoogleDrive\GMGoogleDrive\Public\Request-GDriveAuthorizationCode.ps1:106 char:37
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Request-GDriveAuthorizationCode : You cannot call a method on a null-valued expression.
At line:1 char:12
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I scoped out the module you wrote for this, is there a way to automate this for public access ? or is this strictly meant for manual use? I like the idea, it just seems a little short on automation details... Given all the hard work you apparently put into this... seems like it should be possible to automate
This is the error thrown when uploading files over 2GB:
Set-GDriveItemContent : System.Management.Automation.MethodException: Cannot convert argument "val2", with value: "7325106436", for "Min" to type "System.Int32": "Cannot convert value "7325106436" to type "System.Int32". Error: "Value was either too large or too
small for an Int32."" ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "7325106436" to type "System.Int32". Error: "Value was either too large or too small for an Int32." ---> System.OverflowException: Value was either too large or too
small for an Int32.
at System.Convert.ToInt32(Int64 value)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Management.Automation.LanguagePrimitives.ConvertNumeric(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
--- End of inner exception stack trace ---
at System.Management.Automation.LanguagePrimitives.ConvertNumeric(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at CallSite.Target(Closure , CallSite , Type , Object , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at Set-GDriveItemContent(Closure , FunctionContext )
At C:\windows\system32\windowspowershell\v1.0\Modules\GMGoogleDrive-master\GMGoogleDrive\Public\Add-GDriveItem.ps1:97 char:5
Set-GDriveItemContent @PSBoundParameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Continuation of discussion with @mcc85s in #6
mean it actually uploaded most of my files that way, but I think it has the same general error that 7z has when you try to pipeline a folder structure, if the folders are duplicated ( since multiple files in a folder would mean that... ) then it just errors out.
Your upload method does not allow to determine parent of each file.
look into this:
if cmdlet can support pipeline and you pass this file list
D:\toUoload\file1
D:\ToUpload\file2
D:\ToUpload2\file3
C:\WorkItems\ToUpload3\SomeDirectory\file4
what root folder should be for each file in this list ?
How cmdlet should determine it ?
If it uploaded all files into one folder I think this wouldn't what you want
But if I support pipeline input this question will be raised
I can aggregate all files in PROCESS{}
block and do uploading in END {}
, trying to determine common root... but this break all the pipeline idea :)
May be just use new Add-GDriveFolder
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.