我正在将 Azure 部署脚本从 AzureRM 迁移到 Az,新模块似乎无法打开文件。
有什么想法吗?
我尝试用正斜杠替换反斜杠; 我什至从脚本所在的文件夹中调用它,所以我不需要向它传递完整的文件名,它会正确地将其解析为全名,但它仍然无法打开它。
PS C:\dev\pq\service\scripts\azure\NestedTemplates> Set-AzStorageBlobContent -Container "florin-container" -Context $storageAccount.Context -File ApplicationInsights.json
Set-AzStorageBlobContent : Failed to open file C:\dev\pq\service\scripts\azure\NestedTemplates\ApplicationInsights.json: Illegal characters in path..
At line:1 char:1
+ Set-AzStorageBlobContent -Container "florin-container" -Context $stor ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzStorageBlobContent], TransferException
+ FullyQualifiedErrorId : TransferException,Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentCommand
2019 年 2 月 13 日更新:
我在更大的脚本套件之外创建了一个非常简单的测试用例场景,并且可以非常轻松地重现问题。我将一个名为 test.json 的文件放在 c:\中,它包含一个空的 json 对象,只有大括号,如下面的输出中所示。我正在使用 AzureRM Alias 场景:
PS C:\> type test.json
{}
PS C:\> type C:\test.json
{}
PS C:\> Enable-AzureRmAlias
PS C:\> $sa = Get-AzureRmStorageAccount -ResourceGroupName florin-rg -Name florinsa
PS C:\> Set-AzureStorageBlobContent -Container florin-container -Context $sa.Context -File test.json -Blob test
Set-AzureStorageBlobContent : Failed to open file C:\test.json: Illegal characters in path..
At line:1 char:1
+ Set-AzureStorageBlobContent -Container florin-container -Context $sa. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzStorageBlobContent], TransferException
+ FullyQualifiedErrorId : TransferException,Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentCommand
PS C:\>
最佳答案
阅读 https://github.com/Azure/azure-powershell/issues/8473 的讨论后(归功于上面的评论)并点击https://blogs.msdn.microsoft.com/jeremykuhne/2016/06/09/new-net-path-handling-sneak-peek/的链接我能够在我的机器上解决该问题。
第二个链接文档表示“将名为 powershell.exe.config
的文件放入 C:\Windows\System32\WindowsPowerShell\v1.0
中,其中包含以下内容”。我碰巧已经有了该文件,因此我将内容添加到了现有文件中。
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />
</runtime>
</configuration>
重新启动 PowerShell 后,我现在能够成功执行我的脚本。我更新到 Az
后问题就开始了模块并删除了AzureRm
模块。这有望节省其他人追逐链接的时间。
更新0
也可以通过修改注册表来解决问题。
$registryPath = "HKLM:\SOFTWARE\Microsoft\.NETFramework\AppContext"
New-Item -Path $registryPath
New-ItemProperty -Path $registryPath -Name "Switch.System.IO.UseLegacyPathHandling" -Value "false"
然后重新启动 PowerShell 实例。
关于azure - Set-AzStorageBlobContent 引发异常 : Illegal characters in path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522744/