IT Security News & Blog

Automate File Transfers Like an Expert with PowerShell & Google Cloud

Posted: 30 August 2018

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 To Google Made Simple

Take a look at this script we have put together which takes a file from Ipswitch 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?

Take a look at our definitive guide to Securely Sharing Documents and Files in a Privacy Oriented World.


Auditing and Error Control for 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.

Ipswitch 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

Advanced Cyber Solutions are specialists in managed file transfer, automated transfers and Ipswitch MOVEit 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 Ipswitch MOVEit Automation, you can book a short call by clicking here.


New call-to-action

Topics: Automation, PowerShell, Cloud, Google Cloud

Chris Payne

Written by Chris Payne

Managing Director - Advanced Cyber Solutions