Automate File Transfers Like an Expert with PowerShell & Google Cloud

Today, if you are not embracing the cloud then it would seem you are in a steadily declining minority. Cloud is the buzz term that refuses to die; and so instead we find ourselves in an age of migration toward the cloud or in a state of hybrid network, where the boundaries between cloud and hosted services are blurred.

But I know what you are thinking.

Cloud migration can be a tough world, full of APIs, resource IDs and tenants, where even the simplest of tasks, such as moving a number of files to a cloud storage location is made complicated.

Nobody wants to spend their day dragging and dropping content from one location to another...

...and you don't have to either!

With a little PowerShell scripting, you can be moving files from network to cloud without any hands, that's an automation promise.


PowerShell and Google Drive


Take a look at this script we have put together which takes a file from MOVEit Automation, an automated file transfer which we highly recommend, and moves it to a designated Google Cloud Drive.

# Change this to the file you want to upload
$sourceFile = $miaclient.MICacheFilename()

# Get the source file contents and details, encode in base64
$sourceItem = Get-Item $sourceFile
$sourceBase64 = [Convert]::ToBase64String([IO.File]::ReadAllBytes($miaclient.MIGetOriginalFilename()))
$sourceMime = [System.Web.MimeMapping]::GetMimeMapping($miaclient.MIGetOriginalFilename())

# If uploading to a Team Drive, set this to 'true'
$supportsTeamDrives = 'false'

# Set the file metadata
$uploadMetadata = @{
originalFilename = $miaclient.MIGetOriginalFilename()
name = $miaclient.MIGetOriginalFilename()
description = $sourceItem.VersionInfo.FileDescription
#parents = @('teamDriveid or folderId') # Include to upload to a specific folder
#teamDriveId = ‘teamDriveId’ # Include to upload to a specific teamdrive

# Set the upload body
$uploadBody = @"
Content-Type: application/json; charset=UTF-8
$($uploadMetadata | ConvertTo-Json)
Content-Transfer-Encoding: base64
Content-Type: $sourceMime

# Set the upload headers
$uploadHeaders = @{
"Authorization" = "Bearer $accessToken"
"Content-Type" = 'multipart/related; boundary=boundary'
"Content-Length" = $uploadBody.Length

# Perform the upload
$response = Invoke-RestMethod -Uri "$supportsTeamDrives" -Method Post -Headers $uploadHeaders -Body $uploadBody

Not so difficult right?


Auditing and Error Control for Automated File Transfers


With file transfers to Google Cloud being automated, you might want to look at including some reporting and auditing capabilities to keep a track of your masterpiece.

MOVEit Automation is a great tool which allows you to automate the movement of files and script execution, such as the one above.

It contains capabilities to be able to audit the movement of every file, the time consumed moving it and the final outcome. In addition it can automate error handling, such as what to do when Google Cloud becomes unavailable or if the file is locked and cannot be moved.

Ipswitch MOVEit Automation Automated File Transfers

Pro2col are specialists in managed file transfer, automated transfers and MFT solutions like MOVEit, GoAnywhere, Globalscape and Axway solutions. Servicing the Northern European market with nearly a decade of product experience and awards to match.

If you would like to speak to one of our solution specialists about automated file movements and Managed File Transfer you can book a short call by clicking here.


About the Author

headshot of Christ Payne, Director of Strategic Alliances and Technical at Pro2col


Chris Payne is the Director of Strategic Alliances and Technical at Pro2col, with decades of experience in software management and Managed File Transfer solutions. Chris is not your traditional techie with server racks under the stairs. He advocates for a healthy work/life balance, saving his love for technology for work and developing his passion for craft beer at home. Chris is a qualified brewer and has on occasion whipped out the brewing equipment. He’ll be up for a Friday pint.

Find out more about Chris Payne here.