Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-Variables.ps1 script Unexpected token '?' in expression or statement #150

Open
henrydyer opened this issue Feb 23, 2024 · 6 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@henrydyer
Copy link

Describe the bug

When running the Set-Variables.ps1 script, I get the following error:

PS C:\dev\CodeSamples\TasksTracker.ContainerApps> .\Set-Variables.ps1
At C:\dev\CodeSamples\TasksTracker.ContainerApps\Set-Variables.ps1:74 char:41

  • "Write-Host "Set $i variable$($i -eq 1 ? '' : 's')."" | Out-File -F ...
  •                                     ~
    

Unexpected token '?' in expression or statement.
At C:\dev\CodeSamples\TasksTracker.ContainerApps\Set-Variables.ps1:76 char:43

  • Write-Host "nWrote $i variable$($i -eq 1 ? '' : 's') to $file.n"
  •                                       ~
    

Unexpected token '?' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken

I am not particularly familiar with PowerShell, but I have tried to adjust the quotes, etc. in those commands, but to no avail. Would you mind offering me some guidance please?

Expected behavior

From the workshop instructions: "Execute the script. You will do this repeatedly throughout the modules. The output of the script will inform you how many variables are written out."

Actual behavior

As per the description:

At C:\dev\CodeSamples\TasksTracker.ContainerApps\Set-Variables.ps1:74 char:41

  • "Write-Host "Set $i variable$($i -eq 1 ? '' : 's')."" | Out-File -F ...
  •                                     ~
    

Unexpected token '?' in expression or statement.
At C:\dev\CodeSamples\TasksTracker.ContainerApps\Set-Variables.ps1:76 char:43

  • Write-Host "nWrote $i variable$($i -eq 1 ? '' : 's') to $file.n"
  •                                       ~
    

Unexpected token '?' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken

Reproduction Steps

Just run the script in the latest (or any I think) version of PowerShell.

@simonkurtz-MSFT simonkurtz-MSFT self-assigned this Feb 23, 2024
@simonkurtz-MSFT
Copy link
Contributor

Hi @henrydyer, I just followed our instructions and see the output, as expected, as Wrote 1 variable to ./Variables.ps1. I run PowerShell 7.4.1.

Could you double-check your steps, please, and inform us what PowerShell version you are using?

@henrydyer
Copy link
Author

henrydyer commented Feb 26, 2024 via email

@simonkurtz-MSFT
Copy link
Contributor

Hi @henrydyer, you are welcome! I'm so sorry you are running into trouble there. I have fairly exclusively run this on PowerShell 7 in Windows 11, so I can't speak to 5.1 on Windows 10 much. Given that this seems to revolve around an informative console output only and perhaps not the core functionality, could you try to comment it out and see if everything else from there on goes as desired, please? If you are so inclined, I would also love a PR if you tinker with the output and get it working.

Thank you!

@henrydyer
Copy link
Author

henrydyer commented Feb 26, 2024 via email

@simonkurtz-MSFT simonkurtz-MSFT added the bug Something isn't working label Feb 26, 2024
@simonkurtz-MSFT
Copy link
Contributor

Hi @henrydyer, awesome progress!

It looks like you are running into a difference between Windows PowerShell built on .NET Framework and the open-sourced PowerShell built on .NET Core. It appears that your VS Code is using the newer PowerShell version via its extension.

I typically use Windows Terminal and PowerShell in my setup. Not to get too much beyond the filed issue, but it may be worthwhile for you to explore whether that setup could provide some advantages.

I'll keep the issue open, but I don't expect to do any active development on it as it's a relatively benign issue, all-in-all, and a work-around exists. I thank you for filing it, and I hope that you enjoy working with Azure Container Apps! Reach out if you have any questions, please.

@henrydyer
Copy link
Author

henrydyer commented Feb 26, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants