Why weird assignment from variable inside Powershell switch statement?











up vote
2
down vote

favorite












I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes and = $No in this code snippet:



Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}


I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?










share|improve this question


















  • 3




    = is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test' or function = { $args } is another syntax
    – TheIncorrigible1
    Nov 21 at 22:58








  • 1




    The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
    – Bacon Bits
    2 days ago















up vote
2
down vote

favorite












I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes and = $No in this code snippet:



Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}


I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?










share|improve this question


















  • 3




    = is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test' or function = { $args } is another syntax
    – TheIncorrigible1
    Nov 21 at 22:58








  • 1




    The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
    – Bacon Bits
    2 days ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes and = $No in this code snippet:



Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}


I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?










share|improve this question













I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes and = $No in this code snippet:



Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}


I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?







powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 22:55









jacobsee

65131230




65131230








  • 3




    = is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test' or function = { $args } is another syntax
    – TheIncorrigible1
    Nov 21 at 22:58








  • 1




    The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
    – Bacon Bits
    2 days ago














  • 3




    = is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test' or function = { $args } is another syntax
    – TheIncorrigible1
    Nov 21 at 22:58








  • 1




    The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
    – Bacon Bits
    2 days ago








3




3




= is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test' or function = { $args } is another syntax
– TheIncorrigible1
Nov 21 at 22:58






= is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test' or function = { $args } is another syntax
– TheIncorrigible1
Nov 21 at 22:58






1




1




The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
2 days ago




The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
2 days ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










UPDATE: This issue has been resolved.





Looks to me like the variable name that was getting the assignment was deleted in a change back in August.



$PublishSettings = $Yes


Was changed to:



= $Yes


And:



$PublishSettings = $No


Was changed to:



= $No


Looks like poor search and replace.



I've created an issue for the problem at GitHub.






share|improve this answer






























    up vote
    1
    down vote













    There are many characters that are valid in a function (or variable) name; this includes the = symbol. What you're observing is a function or alias.



    Examples:



    # standard function
    function =
    {
    return $args
    }

    # accessing the function: drive
    ${Function:=} = {
    return $args
    }

    # defining a new alias
    New-Alias -Name = -Value Get-Variable

    # using the Alias attribute
    function Test-Thing
    {
    [Alias('=')]
    param()

    return $args
    }





    share|improve this answer























    • Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
      – jacobsee
      Nov 27 at 19:05










    • @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
      – TheIncorrigible1
      Nov 27 at 19:09










    • There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
      – jacobsee
      Nov 27 at 19:37










    • @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
      – TheIncorrigible1
      Nov 27 at 19:44








    • 1




      @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
      – TheIncorrigible1
      Nov 27 at 20:57











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421586%2fwhy-weird-assignment-from-variable-inside-powershell-switch-statement%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    UPDATE: This issue has been resolved.





    Looks to me like the variable name that was getting the assignment was deleted in a change back in August.



    $PublishSettings = $Yes


    Was changed to:



    = $Yes


    And:



    $PublishSettings = $No


    Was changed to:



    = $No


    Looks like poor search and replace.



    I've created an issue for the problem at GitHub.






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      UPDATE: This issue has been resolved.





      Looks to me like the variable name that was getting the assignment was deleted in a change back in August.



      $PublishSettings = $Yes


      Was changed to:



      = $Yes


      And:



      $PublishSettings = $No


      Was changed to:



      = $No


      Looks like poor search and replace.



      I've created an issue for the problem at GitHub.






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        UPDATE: This issue has been resolved.





        Looks to me like the variable name that was getting the assignment was deleted in a change back in August.



        $PublishSettings = $Yes


        Was changed to:



        = $Yes


        And:



        $PublishSettings = $No


        Was changed to:



        = $No


        Looks like poor search and replace.



        I've created an issue for the problem at GitHub.






        share|improve this answer














        UPDATE: This issue has been resolved.





        Looks to me like the variable name that was getting the assignment was deleted in a change back in August.



        $PublishSettings = $Yes


        Was changed to:



        = $Yes


        And:



        $PublishSettings = $No


        Was changed to:



        = $No


        Looks like poor search and replace.



        I've created an issue for the problem at GitHub.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered Nov 27 at 22:35









        Bacon Bits

        20.4k42939




        20.4k42939
























            up vote
            1
            down vote













            There are many characters that are valid in a function (or variable) name; this includes the = symbol. What you're observing is a function or alias.



            Examples:



            # standard function
            function =
            {
            return $args
            }

            # accessing the function: drive
            ${Function:=} = {
            return $args
            }

            # defining a new alias
            New-Alias -Name = -Value Get-Variable

            # using the Alias attribute
            function Test-Thing
            {
            [Alias('=')]
            param()

            return $args
            }





            share|improve this answer























            • Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
              – jacobsee
              Nov 27 at 19:05










            • @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
              – TheIncorrigible1
              Nov 27 at 19:09










            • There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
              – jacobsee
              Nov 27 at 19:37










            • @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
              – TheIncorrigible1
              Nov 27 at 19:44








            • 1




              @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
              – TheIncorrigible1
              Nov 27 at 20:57















            up vote
            1
            down vote













            There are many characters that are valid in a function (or variable) name; this includes the = symbol. What you're observing is a function or alias.



            Examples:



            # standard function
            function =
            {
            return $args
            }

            # accessing the function: drive
            ${Function:=} = {
            return $args
            }

            # defining a new alias
            New-Alias -Name = -Value Get-Variable

            # using the Alias attribute
            function Test-Thing
            {
            [Alias('=')]
            param()

            return $args
            }





            share|improve this answer























            • Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
              – jacobsee
              Nov 27 at 19:05










            • @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
              – TheIncorrigible1
              Nov 27 at 19:09










            • There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
              – jacobsee
              Nov 27 at 19:37










            • @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
              – TheIncorrigible1
              Nov 27 at 19:44








            • 1




              @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
              – TheIncorrigible1
              Nov 27 at 20:57













            up vote
            1
            down vote










            up vote
            1
            down vote









            There are many characters that are valid in a function (or variable) name; this includes the = symbol. What you're observing is a function or alias.



            Examples:



            # standard function
            function =
            {
            return $args
            }

            # accessing the function: drive
            ${Function:=} = {
            return $args
            }

            # defining a new alias
            New-Alias -Name = -Value Get-Variable

            # using the Alias attribute
            function Test-Thing
            {
            [Alias('=')]
            param()

            return $args
            }





            share|improve this answer














            There are many characters that are valid in a function (or variable) name; this includes the = symbol. What you're observing is a function or alias.



            Examples:



            # standard function
            function =
            {
            return $args
            }

            # accessing the function: drive
            ${Function:=} = {
            return $args
            }

            # defining a new alias
            New-Alias -Name = -Value Get-Variable

            # using the Alias attribute
            function Test-Thing
            {
            [Alias('=')]
            param()

            return $args
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 27 at 19:23

























            answered Nov 21 at 23:10









            TheIncorrigible1

            9,29631334




            9,29631334












            • Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
              – jacobsee
              Nov 27 at 19:05










            • @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
              – TheIncorrigible1
              Nov 27 at 19:09










            • There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
              – jacobsee
              Nov 27 at 19:37










            • @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
              – TheIncorrigible1
              Nov 27 at 19:44








            • 1




              @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
              – TheIncorrigible1
              Nov 27 at 20:57


















            • Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
              – jacobsee
              Nov 27 at 19:05










            • @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
              – TheIncorrigible1
              Nov 27 at 19:09










            • There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
              – jacobsee
              Nov 27 at 19:37










            • @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
              – TheIncorrigible1
              Nov 27 at 19:44








            • 1




              @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
              – TheIncorrigible1
              Nov 27 at 20:57
















            Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
            – jacobsee
            Nov 27 at 19:05




            Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
            – jacobsee
            Nov 27 at 19:05












            @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
            – TheIncorrigible1
            Nov 27 at 19:09




            @jacobsee I'm assuming there's something that looks like $Yes = switch(condition) { somewhere in the codebase. If the variable is undefined, it returns $null
            – TheIncorrigible1
            Nov 27 at 19:09












            There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
            – jacobsee
            Nov 27 at 19:37




            There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
            – jacobsee
            Nov 27 at 19:37












            @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
            – TheIncorrigible1
            Nov 27 at 19:44






            @jacobsee That's where your misunderstanding is coming - = is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =. { } is an empty scriptblock being passed to the = function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
            – TheIncorrigible1
            Nov 27 at 19:44






            1




            1




            @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
            – TheIncorrigible1
            Nov 27 at 20:57




            @jacobsee Yeah, I reviewed the project and there's no definition for a = function or alias so that line of code would throw an exception.
            – TheIncorrigible1
            Nov 27 at 20:57


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421586%2fwhy-weird-assignment-from-variable-inside-powershell-switch-statement%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)