[int]$name = Read-Host Enter the KB numberIf ($name -is [int]) { wusa /uninstall /kb:$name write-Host "This will uninstall windows update KB$name"} else { write-Host "Enter only the number"}
Here in this PowerShell scripts, whenever a characters is typed is returns an error instead of message "Enter only the number".
PS C:\Users\User\Desktop> .\Test.ps145454Enter the KB number: asfsCannot convert value "asfs" to type "System.Int32". Error: "Input string was not in a correct format."At C:\Users\User\Desktop\Test.ps1:5 char:1+ [int]$name = Read-Host Enter the KB number+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidArgument: (:) [], RuntimeException+ FullyQualifiedErrorId : InvalidCastFromStringToInteger
This will uninstall windows update KB0