Set-AzStorageBlobContent引发异常:路径中的非法字符 [英] Set-AzStorageBlobContent throws exception: Illegal characters in path
问题描述
我正在将Azure部署脚本从AzureRM迁移到Az,看来新模块无法打开文件.
I am migrating out Azure deployment scripts from AzureRM to Az and it seems that the new module has trouble opening the files.
有什么想法吗?
我尝试用正斜杠替换反斜杠; 我什至从脚本所在的文件夹中调用了它,因此不需要传递完整的文件名,它可以将其正确解析为一个全名,但是仍然无法打开它.
I tried replacing backward slashes with forward slashes; I even called it from the folder where the scripts are, so I don't need to pass it the full file name, and it resolves it to a full name correctly, but it still can't open it.
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
2/13/19更新:
2/13/19 Update:
我在更大的脚本套件之外创建了一个非常简单的测试用例场景,可以很容易地重现问题.我在c:\中放置了一个名为test.json的文件,它包含一个空的json对象,只是花括号,如下面的输出所示.我正在使用AzureRM Alias方案:
I created a very simple test case scenario, outside of our bigger script suite and can very easily recreate the problem. I put a file called test.json in c:\, it contains an empty json object, just the curly braces, as you can see in the output below. I am using the AzureRM Alias scenario:
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/我能够解决机器上的问题.
After reading the discussion from https://github.com/Azure/azure-powershell/issues/8473 (credit to comments above) and following the link to https://blogs.msdn.microsoft.com/jeremykuhne/2016/06/09/new-net-path-handling-sneak-peek/ I was able to resolve the problem on my machine.
第二个链接文档说将具有以下内容的名为powershell.exe.config
的文件拖放到C:\Windows\System32\WindowsPowerShell\v1.0
中".我碰巧已经有了文件,所以将内容添加到现有文件中.
The second linked document says to "Drop a file called powershell.exe.config
in C:\Windows\System32\WindowsPowerShell\v1.0
with the following contents". I happened to already have the file so I added the content to my existing file.
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />
</runtime>
</configuration>
重新启动PowerShell之后,我现在能够成功执行脚本.我更新到Az
模块并删除了AzureRm
模块后,问题开始了.希望这可以节省其他人追踪链接的时间.
After restarting PowerShell, I was now able to successfully execute my scripts. The problem started after I updated to the Az
module and removed the AzureRm
module. This will hopefully save others time from chasing links.
更新0
还可以修改注册表以解决该问题.
It is also possible to modify the registry to solve the problem.
$registryPath = "HKLM:\SOFTWARE\Microsoft\.NETFramework\AppContext"
New-Item -Path $registryPath
New-ItemProperty -Path $registryPath -Name "Switch.System.IO.UseLegacyPathHandling" -Value "false"
然后重新启动PowerShell实例.
Then restart the PowerShell instance.
这篇关于Set-AzStorageBlobContent引发异常:路径中的非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!