Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The Imperfect Lab: Azure Files
# Created a new storage account:
New-AzureStorageAccount -StorageAccountName <storageaccountname> -Location ‘West US’
# Captured the Access Key as a variable:
$storageAccessKey = (Get-AzureStorageKey –StorageAccountName <storageaccountname>).Primary
# Created a security context with the access key:
$storageContext = New-AzureStorageContext <storageaccountname> $storageAccessKey
# Created a new share:
$share = New-AzureStorageShare <sharename> -Context $storageContext
# Created a directory in the share. I called mine "powershell" in this example:
New-AzureStorageDirectory -Share $share -Path powershell
# Upload a file to my new directory:
Set-AzureStorageFileContent -Share $share -Source "localfilepath" -Path powershell
# To check that it made it:
Get-AzureStorageFile -Share $share -Path powershell
# Add a persistent mapped drive: (If you don't want to RDP to the machine, you can do this from the command line of your remote machine by opening a PS-Session, just note that the credentials won't be persistent that way and your mapping won't be retained after a reboot.)
cmdkey /add:<storageaccount>.file.core.windows.net /user:<sharename> /pass:<accesskey>
Net use z: \\<storageaccount>.file.core.windows.net\<sharename>
# Alternatively, if you don't have persistent credentials, you can just pass them along right with the net use command:
net use z: \\imperfectfiles.file.core.windows.net\imperfectshare /p:no /u:imperfectfiles $storageAccessKey
# Use PS-Session commands remotely, yet access files that are stored locally on the VM, like CSV files or to write logs. And if you want to delete files, use REMOVE instead of SET, or GET if you want to download them. For example:
Remove-AzureStorageFile –Share $share –Path [foldername]/[filename]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.