Powershell Null or Empty Command Line Options

I have a test.ps1 script as follows:

param(     
      $a = "ValueA"
)

now if you call it from the command line from my msbuild project file as follows

. \ test.ps1 -a "". \ test.ps1 -a $ null

it does not set the default value "ValueA" to $ a. I would like to set the default "Value" to $ a, even if the user passes zero or empty values ​​to it. I know I can use if construct, but I was wondering if there is a faster way to achieve this. Any idea?

+3
source share
2 answers

, , ( : - , ).

0

(  $ a = "ValueA" )

$a = ( "ValueA", $a) [[int] [bool] $a]

0

Source: https://habr.com/ru/post/1785176/


All Articles