Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文件上载到Azure文件存储的Powershell脚本_Powershell_Azure_Vbscript - Fatal编程技术网

将文件上载到Azure文件存储的Powershell脚本

将文件上载到Azure文件存储的Powershell脚本,powershell,azure,vbscript,Powershell,Azure,Vbscript,所以我有一个Azure文件存储,你也可以映射一个集合驱动器。 目前,它被选为X驱动器,但我遇到了一个小问题,因为有时我会因为驱动器闲置而失去与驱动器的连接 我遵循这个指南,它为我提供了如何设置evrything(“”)的方法 我想用下面的脚本通过一个定时计划将一些文件移动到那个特定的文件夹 With CreateObject("Scripting.FileSystemObject") .MoveFile "YourFolder\*.*", "X:\AzureFolder" End Wit

所以我有一个Azure文件存储,你也可以映射一个集合驱动器。 目前,它被选为X驱动器,但我遇到了一个小问题,因为有时我会因为驱动器闲置而失去与驱动器的连接

我遵循这个指南,它为我提供了如何设置evrything(“”)的方法

我想用下面的脚本通过一个定时计划将一些文件移动到那个特定的文件夹

With CreateObject("Scripting.FileSystemObject")
    .MoveFile "YourFolder\*.*", "X:\AzureFolder"
End With
上面的vbscript工作起来很有魅力,但正如我提到的,azure文件存储实际上处于空闲状态,并且工作失败

因此,我现在的计划是实际创建一个powershell脚本,将身份验证值设置为硬变量,然后像上面的vbscript那样移动文件。 有人知道是否有人在开源代码中做过类似的事情吗

我确实在网上找到了一些脚本(“”) 但它们似乎不起作用

如果有人能给我指出正确的方向或提供一份有用的指南,我会很高兴的


谢谢

以下几行将本地文件上载到azure blob存储中

$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName ` -StorageAccountKey $StorageAccountKey
$ContainerName = "webimages"
New-AzureStorageContainer -Name $ContainerName -Context $ctx -Permission Blob
$localFileDirectory = "X:\Temp\AzureFilesToUpload\"
$files = Get-ChildItem -Path $localFileDirectory -Recurse -File
foreach($file in $files)
{
    $localFile = $localFileDirectory+$file
    Set-AzureStorageBlobContent -File $localFile -Container $ContainerName `-Blob $BlobName -Context $ctx
}
Get-AzureStorageBlob -Container $ContainerName -Context $ctx | Select Name
下面几行将本地文件上载到存储帐户的azure文件部分,而不是blob

$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName ` -StorageAccountKey $StorageAccountKey  
$s = New-AzureStorageShare $filesharename –Context $ctx # to create new file share
$localFileDirectory = "X:\Temp\AzureFilesToUpload\"
$files = Get-ChildItem -Path $localFileDirectory -Recurse -File  
foreach($file in $files)  
{  
    $localFile = $localFileDirectory+$file  
    Set-AzureStorageFileContent –Share $s –Source $localFile  
}  
  # if you don’t want them in the root folder of the share, but in a subfolder?  
New-AzureStorageDirectory –Share $s –Path $foldername
foreach($file in $files)  
{  
    $localFile = $localFileDirectory+$file  
    Set-AzureStorageFileContent –Share $s –Source $localFile –Path $foldername  
}  

我已经看到了这一点,但是Azure Blob存储与Azure文件存储相比没有区别吗?我在上面的编辑中列出了通过powershell连接Azure文件存储的线路。Azure文件存储使用标准SMB协议提供共享存储。Azure虚拟机和云服务可以通过装载的共享跨应用程序组件共享文件数据,本地应用程序可以通过文件服务REST API访问共享中的文件数据,而Blob存储存储非结构化对象数据。blob可以是任何类型的文本或二进制数据,例如文档、媒体文件或应用程序安装程序。Blob存储也称为对象存储。我在提供的脚本中添加了一些注释,因为我不知道应该在正确的位置放置什么。如果看起来正确,请查看下面的内容。$ctx=新AzureStorageContext MyStorageAccountName$StorageAccountName`TheStorageAccountKey EndsWith==通常情况下$StorageAccountKey$s=新AzureStorageShare$filesharename fileShareText?这是你的名字吗$ctx新AzureStorageDirectory共享名$s路径在共享中$foldername foreach($files中的文件){$localFile=$localFileDirectory+$file Set AzureStorageFileContent共享名$s Lokalfilder文件存储在何处$localFile PathInShare?$foldername}示例$StorageAccountKey=AxgCWYNr0+2LT7ADYZPRORAUGHFJ6XYRE17GHACXCUCD3VLHNSHERF1LJFRWJOQXAYOAZHCH750/ju9j3ncTw==$filesharename=images#它是文件共享名$foldername=webimages#它是共享中的子文件夹名。为了更好地理解$s=新AzureStorageShare图像–上下文$ctx#如果azure门户中不存在文件共享$s=获取AzureStorageShare映像–上下文$ctx#如果azure门户中已存在文件共享新AzureStorageDirectory–共享$s–路径WebImages您可以参考: