Reputation: 71
I am migrating out Azure deployment scripts from AzureRM to Az and it seems that the new module has trouble opening the files.
Any ideas?
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 Update:
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:\>
Upvotes: 2
Views: 3158
Reputation: 2908
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.
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>
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.
UPDATE 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"
Then restart the PowerShell instance.
Upvotes: 7
Reputation: 176
None of the solutions above worked for me. The only way to beat it was to use Azure.Storage module instead of Az.Storage, and Set-AzureStorageBlobContent instead of Set-AzStorageBlobContent
So:
1) Install-Module Azure.Storage -AllowClobber
(without -AllowClobber it fails because of Azure.Profile)
2) Import-Module Azure.Storage
3) In the script replace Set-AzStorageBlobContent
command with Set-AzureStorageBlobContent
Upvotes: 0
Reputation: 42063
If your AzureRM
command works fine, the easiest way to run the AzureRM
command with Az
module is just executed Enable-AzureRmAlias
at first, then run your AzureRM
command, it will also work.
Also, I test the Az
command in local, it should work fine.
$context = New-AzStorageContext -StorageAccountName "<StorageAccountName>" -StorageAccountKey "xxxxxxx"
Set-AzStorageBlobContent -Container "111" -File "C:\Users\joyw\Desktop\cosmos.json" -Context $context
These are my powershell modules, you could check them.
Upvotes: 1