My restock script died on the first row of a Columbus store’s inventory CSV with “Cannot convert value to type System.Int32” and “Input string was not in a correct format.” PowerShell tried to read text as a number, and the text didn’t fit.
The quickest safe fix is to test the conversion first:
$qty = 0
if ([int]::TryParse($value, [ref]$qty)) { $qty } else { "Not a number: '$value'" }
In this tutorial, I’ll show you every cause of input string was not in a correct format in PowerShell, from [int] and [double] casts to culture separators, hidden characters and the -f operator.
Quick answer: inspect the value, then clean it, use [long], pass the right culture to Parse(), or convert with -as [int] or TryParse.
What does “Cannot convert value to type System.Int32” mean?
System.Int32 is the .NET type behind [int]. It holds whole numbers from -2,147,483,648 to 2,147,483,647. You get the error when a cast, a typed variable or a typed parameter receives something that isn’t one:
$qty = '12 boxes'
$total = [int]$qty * 4
Output (PowerShell 7):
InvalidArgument: C:\psfaqs\err.ps1:2
Line |
2 | $total = [int]$qty * 4
| ~~~~~~~~~~~~~~~~~~~~~~
| Cannot convert value "12 boxes" to type "System.Int32". Error: "The input string '12 boxes' was not in a correct
| format."

The text after Error: is the real reason. Windows PowerShell 5.1 words it a little differently and adds the error ID InvalidCastFromStringToInteger:
