0

I'm working on a script and while searching for something on the internet, I found these lines in PowerShell:

Function Add-Script ([string] $script, [bool] $reboot = $false) {
    $script:scripts += ,@($script, $reboot)
}

I tried to search in the Microsoft documentation but I'm not finding any concept related to the $script:scripts part and I don't understand why there is a comma after the +=.

The $scripts object is created with a global scope and we can use it if by calling '$scripts'. It will contain an array of array and will become bigger if we call this function many times.

So is there anyone who understand the this last line of code and maybe send the documentation related to it ? It would be really nice.

Thanks !

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    `$script:scripts` is just the name of a variable defined in the Script scope, nothing else than that. [`,` represents the unary operator](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2#comma-operator-) in this case. It's ensuring that each array being added to `$script:scripts` will not be enumerated hence becoming an array of arrays – Santiago Squarzon Dec 26 '22 at 17:00
  • 1
    Oh, thank you so much. I didn't notice it was a script scope. I got mixed up with the $script variable. And about the ',', its good to know :) – justANormalGuy Dec 26 '22 at 17:45

0 Answers0