1

我创建了 az Azure 文件共享,我想在其中存储一些 SharePoint 预配文件、模板和 xml。文件被复制到共享并准备好使用。

我知道可用于检索单个文件的 Get-AzureStorageFileContent 命令,但我需要将此共享视为共享,因为这些文件是从 PnP 配置模板中引用的,例如:

  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="webparts\head.xml"/>

当我在本地或从网络共享运行脚本时,这工作正常。所以,我的问题是,我怎样才能使用 UNC 路径或将其映射为网络驱动器?

根据文档,我应该可以将它用作 smb 共享,但是当我尝试连接时,我收到此错误:

New-SmbMapping: 无法连接到 CIM 服务器。指定的服务不作为已安装的服务存在。

New-PSDriveAzure Powershell 中不存在。我在 Azure 中发现这是一个模块,但是当其中一个需要更新 Azure 中的 .Net 时,我停止安装依赖项。

有人可以给我一个端到端的指南,我怎样才能使用 Azure 文件共享实现真正的文件共享功能?

编辑:如果我可以将所有文件从共享复制到当前临时文件夹,那么可接受的解决方法是,因为从那里我可以使用$env:TEMP.

4

2 回答 2

3

更新:递归地将所有文件和文件夹复制到 $env:temp

powershell 运行手册中的代码:

function Get-AzureFiles
{
param([string]$filesharename = 'testfolder', #replace with your own fileshare name
      [string]$username = 'your account name',
      [string]$password = 'your account key', 
      [string]$destination=$env:TEMP+"\", #note there is a slash at the end
      [string]$path="")

      $temp = $env:TEMP

      # get the context
      $context = New-AzureStorageContext -StorageAccountName $username -StorageAccountKey $password

      # get all files and directories
      if($path -eq "")
      {
      $content = Get-AzureStorageFile -ShareName $filesharename -Context $context
      }
      else
      {
      $content = Get-AzureStorageFile -ShareName $filesharename -Context $context -Path $path | Get-AzureStorageFile
      }

      if(!(test-path $destination))
        {
        mkdir $destination
        }

      foreach($c in $content)
      {
        $p = $c.uri.LocalPath -replace "$($c.share.name)/" ,''
        #write-host "the value p is: $p"

        #if it's a directory in fileshare
        if($c.gettype().name -eq "CloudFileDirectory")
        {
           # Write-Host "$($c.share.name) is a directory"
            $destination =$temp + $c.uri.PathAndQuery -replace "/","\"

            #create the folder locally
            if(!(test-path $destination))
            {
            mkdir $destination
            #write-host "the new directory $destination is created locally."
            }

            #define the folder path in fileshare
            $path = ($c.uri.localpath -replace "/$filesharename/" , "") -replace "/","\"

            Get-AzureFiles -destination $destination -path $path

        }
        #if it's a file
        elseif($c.gettype().name -eq "CloudFile")
        {         
         $s = $temp + $c.uri.PathAndQuery -replace "/","\"
         #Write-Output "downloading --- $s"

         $d1 = $c.uri.PathAndQuery -replace "/","\"
         $d1 = $d1.remove($d1.LastIndexOf("\")+1)

         $destination =$temp + $d1



            #create the folder locally
            if(!(test-path $destination))
            {
            mkdir $destination
            #write-host "the new directory $destination is created locally."
            }
         $path_temp = $c.uri.PathAndQuery -replace "/$filesharename/",""

         Get-AzureStorageFileContent -ShareName $filesharename -Path $path_temp  -Destination $destination -Context $context        
        }
      }
}


function do-test
{
get-AzureFiles

# you can operate the files copied to $env:temp
dir $env:TEMP\testfolder
dir $env:TEMP\testfolder\t1
dir $env:TEMP\testfolder\t1\t1sub
}

do-test

测试结果:

在此处输入图像描述

我在 Azure 门户中的文件共享结构:

在此处输入图像描述

于 2019-01-10T08:30:24.017 回答
0

看起来您收到的错误与 DNS 服务器上的权限有关,此线程提供以下解决方案:

在 DNS 服务器/DC 上添加这两个角色:DnsAdmins 和 WinRMRemoteWMIUsers__。然后在 DNS 服务器上执行以下操作:

*1。打开计算机管理控制台。右键单击 WMI 控件(在服务和应用程序下),然后单击属性。2. 在新打开的窗口中,单击安全选项卡。

  1. 展开根树,然后单击节点 CIMV2,然后单击按钮安全
  2. 在新打开的窗口中,单击高级按钮。
  3. 在新打开的窗口中,单击权限选项卡下的按钮添加。
  4. 在新打开的窗口中,单击“选择主体”,然后搜索并添加组 WinRMRemoteWMIUsers__ 作为主体,然后单击确定。
  5. 在应用于中,选择“此命名空间和子命名空间”。
  6. 对于权限,请检查“执行方法”、“启用帐户”和“远程启用”</li>
  7. 单击确定三次。
  8. 然后导航到节点 Root – Microsoft – Windows – DNS。做同样的事情,为 WinRMRemoteWMIUsers 添加权限。
  9. 重新启动服务“Windows Management Instrumentation。
  10. 检查问题是否已解决。*

这是完整的 MS官方文档,其中还提供了在本地连接驱动器的步骤

于 2019-01-09T17:28:26.050 回答