PowerShellスクリプトで変数を初期化(null)する
Use the Remove-Variable cmdlet to initialize (null) variables in PowerShell scripts.
The alias is rv. Specify the name of the variable as an argument, but omit the $ or an error will result.
PS C:\work_ps> $a=1;$a;$a; 1 1 PS C:\work_ps> $a=1;$a;rv a;$a; 1 PS C:\work_ps>
The first command is executed twice with $a;$a;, so “1” is displayed twice.
The next command initializes by typing rv a, so the second $a; is null, so only one “1” is displayed.
There is an easier way to check if it is null.
[string]::isnullorempty(variable name);
Type as above; if True is displayed, it is Null; if False is returned, it is not Null.
PS C:\work_ps> $a=1;rv a;[string]::isnullorempty($a); True PS C:\work_ps>
![株式会社CONFRAGE](https://i0.wp.com/confrage.jp/wp-content/uploads/2018/08/aaaaaaaaa-1.jpg?resize=100%2C100&ssl=1)
コメント