I have the following code which initialises a value to -1:
Set-Variable -Name ID -Value -1 -Scope local
When I do it like this,
$local:ID++
I get the following error:
The ‘++’ operator works only on numbers. The operand is a
‘System.String’.
I thought it will implicitly consider this as int. But, I have to use a workaround which is not neat:
Workaround:
$intVal = [int]$local:ID
$intval ++
Is there another approach?
$id is a string (type $id.gettype() to find its type). In order to initialize it as an integer, put it in parenthesis: