Skip to content

Instantly share code, notes, and snippets.

@DominicCronin
Last active March 24, 2020 11:09
Show Gist options
  • Save DominicCronin/9089012 to your computer and use it in GitHub Desktop.
Save DominicCronin/9089012 to your computer and use it in GitHub Desktop.
Import Export Utilities
function DownloadPackageToFile($packageId, $filePath){
InitImportExport
$downloadService = get-ImportExportServiceClient -type Download
try {
$packageStream = $downloadService.DownloadPackage($packageId, $true)
$fileStream = [IO.File]::Create($filePath)
$packageStream.CopyTo( $fileStream)
}
finally {
if ($fileStream -ne $null) {
$fileStream.Dispose()
}
if ($packageStream -ne $null) {
$packageStream.Dispose()
}
}
}
function UploadPackageFromFile($packageLocation){
InitImportExport
$uploadService = get-ImportExportServiceClient -type Upload
try {
$packageStream = [IO.File]::OpenRead($packageLocation)
$uploadService.UploadPackageStream($packageStream)
}
finally {
if ($packageStream -ne $null){
$packageStream.Dispose()
}
}
}
function WaitForImportExportFinish( $serviceClient, $processId){
InitImportExport
do {
$processState = $serviceClient.GetProcessState($processId)
if ([ProcessState]::Finished,[ProcessState]::Aborted,[ProcessState]::AbortedByUser -contains $processState){
break;
}
sleep 1
} while ($true)
$processState.Value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment