Hi all,
I am new to Bitbucket and am trying to use PowerShell to download a file from the Bitbucket repository. The downloaded file is throwing the below error. Can someone help me with the same.
Below is the code.
clear;
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
# Define your Bitbucket credentials
$username = "username"
$password = "password"
# Convert credentials to Base64
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
# Define the Bitbucket URL of the file you want to download
$bitbucketUrl = "gitbucket link to the file"
# Define the local path where you want to save the downloaded file
$localPath = "C:\Temp\Download\usp_GetTableColumns.sql"
# Download the file using Invoke-WebRequest with authentication headers
Invoke-WebRequest -Uri $bitbucketUrl -OutFile $localPath -Headers @{ Authorization = "Basic $base64AuthInfo" }
# Check if the file was downloaded successfully
if (Test-Path $localPath) {
Write-Host "File downloaded successfully to: $localPath"
} else {
Write-Host "Failed to download the file."
}
