Prevent Variable Expansion?

Welcome Forums General PowerShell Q&A Prevent Variable Expansion?

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #73424

    Topics: 3
    Replies: 6
    Points: -18
    Rank: Member


    Is there any way to stop variable expansion happening with parameter values that are passed to a function?

    For example, if I run the below function and neglect to use single quotes for the parameter value, the double dollar automatic variable is expanded:

    function Test-Parameter {
    Test-Parameter -String stringwithdollars$$

    I realise this is just 'how PowerShell works' but wondered if there is anyway to foolproof this.

  • #73457

    Topics: 21
    Replies: 592
    Points: 1,149
    Helping Hand
    Rank: Community Hero
    Test-Parameter -String 'stringwithdollars$$'
    • #73460

      Topics: 3
      Replies: 6
      Points: -18
      Rank: Member

      Yeah I get that. Just wondering if there's a way to stop things messing up if someone gets lazy with the quotes or mistakenly uses double quotes.

The topic ‘Prevent Variable Expansion?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort