param ( [string]$Path, [string]$Filedrop = 'https://xfer.emberkom.net/filedrop/cmd', [string]$From, [string]$Subject = "Upload from ${Env:COMPUTERNAME}", [string]$Message = "" ) ## Build the from address if it isn't specified If ( !($From) ) { If ( "${Env:USERDOMAIN}" -eq "${Env:COMPUTERNAME}" ) { $From = "${Env:COMPUTERNAME}@localdomain.local".ToLower() } Else { $From = "${Env:COMPUTERNAME}@${Env:USERDOMAIN}".ToLower() } } ## Download required tools $DOWNLOAD_TOOLS_SCRIPT = "https://emberkom.s3.amazonaws.com/management/scripts/Download-Tools.ps1" Try { Invoke-Expression ((New-Object System.Net.WebClient).DownloadString($DOWNLOAD_TOOLS_SCRIPT)) } Catch { Write-Host "Required tools failed to download!" } ## Get the path to the LiquidFilesCLI application If ( Test-Path "${Env:ProgramData}\Emberkom\Tools\LiquidFilesCLI.exe" ) { $LFCLI = "${Env:ProgramData}\Emberkom\Tools\LiquidFilesCLI.exe" } ElseIf ( Test-Path "${Env:AppData}\Emberkom\Tools\LiquidFilesCLI.exe" ) { $LFCLI = "${Env:AppData}\Emberkom\Tools\LiquidFilesCLI.exe" } Else { Write-Host "Could not find LiquidFilesCLI.exe"; exit } ## Get the path to the 7za.exe application If ( Test-Path "${Env:ProgramData}\Emberkom\Tools\7za.exe" ) { $ZIPUTIL = "${Env:ProgramData}\Emberkom\Tools\7za.exe" } ElseIf ( Test-Path "${Env:AppData}\Emberkom\Tools\7za.exe" ) { $ZIPUTIL = "${Env:AppData}\Emberkom\Tools\7za.exe" } Else { Write-Host "Could not find 7za.exe"; exit } ## Set the base args $ARGS = "filedrop /url:${Filedrop} /from:`"${From}`" /subject:`"${Subject}`" /msg:`"${Message}`" /c:s" ## Make sure $Path exists If ( Test-Path $Path ) { ## If $Path is a folder... If ( Test-Path $Path -PathType Container ) { ## Set the archive type $ARCHIVE_TYPE = "7z" ## Set the temporary archive $TEMP_PATH = [System.IO.Path]::GetTempPath() $TEMP_FILE = Split-Path $Path -Leaf $TEMP_ARCHIVE = "${TEMP_PATH}${TEMP_FILE}.${ARCHIVE_TYPE}" ## Delete $TEMP_ARCHIVE if it somehow already exists If ( Test-Path $TEMP_ARCHIVE ) { Remove-Item $TEMP_ARCHIVE -Force } ## Compress the folder into the archive Try { Start-Process -WindowStyle Hidden "${ZIPUTIL}" -ArgumentList "a -r -t${ARCHIVE_TYPE} -w `"${TEMP_ARCHIVE}`" `"${Path}`"" -Wait } Catch { Write-Host "Could not create ${TEMP_ARCHIVE}"; exit } $ARGS = "${ARGS} /f:`"${TEMP_ARCHIVE}`"" } ## If $Path is a file... ElseIf ( Test-Path $Path -PathType Leaf ) { $ARGS = "${ARGS} /f:`"${Path}`"" } ## If $Path doesn't exist... Else { Write-Host "${Path} doesn't exist!"; exit } } ## Upload the file Try { Start-Process -WindowStyle Hidden "${LFCLI}" -ArgumentList "${ARGS}" -Wait } Catch { Write-Host "Upload failed!" } ## Delete the local archive (if it exists) Finally { If ( Test-Path $TEMP_ARCHIVE ) { Remove-Item $TEMP_ARCHIVE -Force } }