Create a file share using PowerShell
The file storage structure of Azure is as follows, the most basic file storage contains the storage account, file sharing, under the file share you can create a file directory, upload files:
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110910484-234548762. PNG "style=" border:0px; "/>
Before you start using PowerShell to create a file share, you need to get an Azure account, install PowerShell, and configure your account, please refer to my previous blog, and don't repeat it here.
-
First, to create an Azure storage account, you need to set the name of your storage, and your storage account is created in that region, such as eastern China:
$StorageAccountName =" Mystorageacctfile "
$Location = "China East"
new-azurestorageaccount– Storageaccountname $StorageAccountName-location $Location
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/ 845013-20160511110912093-760846771.png "style=" border:0px; "/>
 
Get your current storage account key by command, set your current subscription, and the current subscription's storage account:
#得到存储的key值
Get-azurestoragekey-storageaccountname $StorageAccountName
#设置当前订阅的默认存储
Set-azuresubscription-currentstorageaccountname $StorageAccountName-subscriptionid $SubscriptionID
Create a file store for Azure file via PowerShell
#获得Azure存储的上下文
$ctx =new-azurestoragecontext $StorageAccountName $StorageAccountKey
#创建Azure File Sharing Service
$share = New-azurestorageshare $filesharename-context $ctx
#列出当前Azure文件共享服务
Get-azurestorageshare-context $ctx-name $filesharename
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110913702-79872954. PNG "style=" border:0px; "/>
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110915140-1662595912. PNG "style=" border:0px; "/>
Log in to Azure portal and you can see the configured storage account and file services:
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110916515-1734284368. PNG "style=" border:0px; "/>
If you want your file service to implement cross-region redundancy, you can configure the configuration item:
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110917530-1941186477. PNG "style=" border:0px; "/>
So far the file sharing service has been created, so we use PowerShell to use the file sharing service, including creating directories, uploading a file, listing files:
#创建文件共享目录
New-azurestoragedirectory-share $share-path Logs
#上传一个文件到文件共享目录
Set-azurestoragefilecontent-share $share-source D:\hdinsight.publishsettings-Path logs
# list all files in directory
Get-azurestoragefile-share $share-path Logs | Get-azurestoragefile
# List all your files
Get-azurestoragefile-share $share-path Logs | Get-azurestoragefile
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110918937-1759927941. PNG "style=" border:0px; "/>
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/845013/201605/845013-20160511110921171-1377759530. PNG "style=" border:0px; "/>
Like other stores, you can use PowerShell to copy between file and file, file and blob:
Start-azurestoragefilecopy-srcsharename $filesharename-srcfilepath "Logs/hdinsight.publishsettings"- Destsharename $filesharenamenew-destfilepath "logs/hdinsight.publishsettings"-context $ctx-destcontext $ctx
All relevant test scripts have been updated to GitHub and you can download the source code test:
Https://github.com/kingliantop/azurelabs/blob/master/storage/StorageFileShare.ps1
Azure file SMB3.0 files sharing Service (2)