Created
August 15, 2019 14:03
-
-
Save poiriersimon/5223a975c0f40845ee4a781514f6e28a to your computer and use it in GitHub Desktop.
Upload file to Azure Blog Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$StorageAccountName = "Demostorage" | |
$ContainerName = "Democontainer" | |
$BlobDirectory = "BlobDir" | |
$localFilePath = "C:\Temp\" | |
$CredObj = Get-Credential "Enter Storage Account Key Only" | |
Import-Module AzureRM | |
$StorageAccountKey = $CredObj.GetNetworkCredential().Password | |
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey | |
$localFileDirectory = Split-Path $localFilePath | |
$Filename = Split-Path $localFilePath -leaf | |
$localFile = $localFileDirectory + "\" + $Filename | |
$BlobName = $BlobDirectory + "\"+ $Filename | |
Try{ | |
Set-AzureStorageBlobContent -File $localFile -Container $ContainerName -Blob $BlobName -Context $ctx -ErrorAction Stop | |
Remove-item $localFilePath -confirm:$false -force | |
} | |
Catch{ | |
Throw "Can't upload" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment