Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add Stop-GSDataTransfer #381

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions PSGSuite/Public/Data Transfer/Stop-GSDataTransfer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function Stop-GSDataTransfer {
<#
.SYNOPSIS
Stops a Data Transfer in progress

.DESCRIPTION
Stops a Data Transfer in progress

.PARAMETER DataTransferId
The Id of the Data Transfer to stop

.EXAMPLE
Stop-GSDataTransfer -DataTransferId abc123xyz456

Stops the Data Transfer with Id 'abc123xyz456'
#>
[cmdletbinding()]
Param (
[parameter(Mandatory=$true,Position=0)]
[string]
$DataTransferId
)
Begin {
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/admin.datatransfer'
ServiceType = 'Google.Apis.Admin.DataTransfer.datatransfer_v1.DataTransferService'
}
$service = New-GoogleService @serviceParams
}
Process {
try {
$dataTransfer = $service.Transfers.Get($DataTransferId).Execute()
if ($dataTransfer) {
$updateRequest = New-Object Google.Apis.Admin.DataTransfer.datatransfer_v1.Data.DataTransfer -Property @{
Status = "CANCELLED"
}
$service.Transfers.Update($dataTransfer.Id, $updateRequest).Execute()
Write-Verbose "Stopped Data Transfer with Id '$DataTransferId'"
}
else {
Write-Error "Data Transfer with Id '$DataTransferId' not found"
}
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}