Files
management-scripts/Upload-Data.ps1
T

40 lines
1.8 KiB
PowerShell
Raw Normal View History

2021-11-18 21:03:45 -05:00
If ( $LFCLI ) {
2021-11-12 11:10:14 -05:00
## Create the path to $FileToUpload and zip the specified directory if necessary
If ( $(Get-Item $DataToUpload) -is [System.IO.DirectoryInfo] ) {
2021-11-18 21:03:45 -05:00
$FileToUpload = '{0}\{1}.zip' -f $Global:OutputDirectory,$(Split-Path -Leaf $DataToUpload)
2021-11-12 11:10:14 -05:00
Zip-Object -path $DataToUpload -dest $FileToUpload
2021-11-18 21:03:45 -05:00
$DeleteAfterUpload = $true
}
Else {
$FileToUpload = $DataToUpload
$DeleteAfterUpload = $false
2021-11-12 11:10:14 -05:00
}
2021-11-18 21:03:45 -05:00
Install-PSAteraModule
Import-Module -Name PSAtera
Set-AteraAPIKey -APIKey $AteraAPIKey
$LFHost = $(Get-AteraCustomValue -ObjectType Customer -ObjectId 9 -FieldName 'LiquidFiles Host URL').ValueAsString
$FiledropURL = "${LFHost}/filedrop/cmd"
## Set the message properties for the file upload
$From = '{0}@{1}.net' -f $Env:COMPUTERNAME,$($Global:MSPName -replace " ","").ToLower()
$Subject = [System.IO.Path]::GetFileNameWithoutExtension($FileToUpload)
$Message = ""
2021-11-12 11:10:14 -05:00
If ( Test-Path $FileToUpload ) {
LogMsg "Uploading ""${FileToUpload}"""
2021-11-18 21:03:45 -05:00
If ( $DeleteAfterUpload ) {
Try { Start-Process "${LFCLI}" -ArgumentList "filedrop /url:${FiledropURL} /from:""${From}"" /subject:""${Subject}"" /msg:""${Message}"" /c:n /deleteAfterUpload /f:""${FileToUpload}""" -Wait }
Catch { LogErr $_.Exception.Message }
}
Else {
Try { Start-Process "${LFCLI}" -ArgumentList "filedrop /url:${FiledropURL} /from:""${From}"" /subject:""${Subject}"" /msg:""${Message}"" /c:n /f:""${FileToUpload}""" -Wait }
Catch { LogErr $_.Exception.Message }
}
2021-11-12 11:10:14 -05:00
}
Else { LogMsg "The specified file does not exist: ""${FileToUpload}""" }
}
2021-11-18 21:03:45 -05:00
Else { LogMsg "Could not upload any data because the LiquidFiles CLI tool was not found" }