In PowerShell, how do you convert an array value into an integer value?

Question:  In PowerShell, how do you convert an array value into an integer value?

Answer:  Assuming that the value is an integer (e.g., not value that is legal for an array but not an integer), do the following:

1.  Write the array value to a file.
2.  Use the key word trim to eliminate blank space or other characters that would not be supported by the integer data type.
3.  Read the resulting value into a variable (e.g., $a) and convert the value to a string.
4.  Use [int] and [convert] terms:

[int]$newa = [convert]::ToInt32($a)

Leave a comment

Your email address will not be published. Required fields are marked *