SOLVED

Get-AzureStorageFileContent not working in script

%3CLINGO-SUB%20id%3D%22lingo-sub-3369044%22%20slang%3D%22en-US%22%3EGet-AzureStorageFileContent%20not%20working%20in%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3369044%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHi%2C%20I%20need%20help%20with%20one%20thing%20because%20I%20am%20writing%20a%20script%20that%20will%20download%20one%20file%20from%20Azure%20File%20Sever.%20Unfortunately%2C%20I%20cannot%20find%20the%20problem%20and%20the%20cause%20of%20the%20errors.%20When%20I%20run%20the%20script%20without%20saving%2C%20i.e.%20line%20by%20line%20in%20powershell%2C%20it%20works%20fine.%20Unfortunately%2C%20when%20I%20save%20the%20script%20to%20a%20file%20and%20call%20it%20from%20Powershell%2C%20it%20bursts%20with%20errors.%20Does%20anyone%20have%20any%20idea%20what%20this%20is%20caused%20by.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Zrzut%20ekranu%202022-05-13%20094453.png%22%20style%3D%22width%3A%20833px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371373iC6645F4ADD73B156%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Zrzut%20ekranu%202022-05-13%20094453.png%22%20alt%3D%22Zrzut%20ekranu%202022-05-13%20094453.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Zrzut%20ekranu%202022-05-13%20094518.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F371376i703368F5E51CC398%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Zrzut%20ekranu%202022-05-13%20094518.png%22%20alt%3D%22Zrzut%20ekranu%202022-05-13%20094518.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3369044%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Storage%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3369370%22%20slang%3D%22en-US%22%3ERe%3A%20Get-AzureStorageFileContent%20not%20working%20in%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3369370%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1389237%22%20target%3D%22_blank%22%3E%40Rakkos_SSW%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20uneducated%20guess%20is%20the%20script%20file%20is%20saved%20in%20a%20Unicode%20format%20that%20presents%20issues%20when%20called%20from%20your%20PowerShell%20session%2C%20which%20I'm%20further%20guessing%20is%20running%20under%20a%20different%20culture.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBecause%20I'm%20a%20Skippy%20-%20sorry%2C%20Australian%20-%20I'm%20not%20terribly%20familiar%20with%20other%20culture%20settings%20but%20something%20you%20could%20try%20is%20re-saving%20the%20.ps1%20script%20in%20Notepad%20as%20either%20ASCII%20or%20UTF-8%20and%20then%20running%20that.%20It%20might%20also%20pay%20to%20delete%20the%20existing%20hyphens%20first%20and%20re-typing%20them%20while%20in%20Notepad%20before%20re-saving%20the%20script%20(but%20again%2C%20this%20is%20also%20just%20another%20guess%20-%20cultures%20really%20aren't%20my%20strength.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt's%20a%20long%20shot%20and%20I'm%20100%25%20guessing%2C%20but%20the%20fact%20that%20both%20hyphens%20in%20front%20of%20each%20parameter%20within%20the%20red%20error%20message%20have%20translated%20to%20a%20different%20Unicode%20character%20is%20what%20has%20me%20guessing%20in%20this%20direction.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3ELain%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3370053%22%20slang%3D%22en-US%22%3ERe%3A%20Get-AzureStorageFileContent%20not%20working%20in%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3370053%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F314983%22%20target%3D%22_blank%22%3E%40LainRobertson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%20when%20i%20save%20in%20Notepadd%20using%20UTF-8%20BOM%20working%20fine%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, I need help with one thing because I am writing a script that will download one file from Azure File Sever. Unfortunately, I cannot find the problem and the cause of the errors. When I run the script without saving, i.e. line by line in powershell, it works fine. Unfortunately, when I save the script to a file and call it from Powershell, it bursts with errors. Does anyone have any idea what this is caused by.

Zrzut ekranu 2022-05-13 094453.pngZrzut ekranu 2022-05-13 094518.png

2 Replies
best response confirmed by Rakkos_SSW (New Contributor)
Solution

@Rakkos_SSW 

 

My uneducated guess is the script file is saved in a Unicode format that presents issues when called from your PowerShell session, which I'm further guessing is running under a different culture.

 

Because I'm a Skippy - sorry, Australian - I'm not terribly familiar with other culture settings but something you could try is re-saving the .ps1 script in Notepad as either ASCII or UTF-8 and then running that. It might also pay to delete the existing hyphens first and re-typing them while in Notepad before re-saving the script (but again, this is also just another guess - cultures really aren't my strength.)

 

It's a long shot and I'm 100% guessing, but the fact that both hyphens in front of each parameter within the red error message have translated to a different Unicode character is what has me guessing in this direction.

 

Cheers,

Lain

@LainRobertson 

Thanks, when i save in Notepadd using UTF-8 BOM working fine :)