Quantcast
Channel: Active questions tagged powershell-3.0 - Stack Overflow
Viewing all articles
Browse latest Browse all 120

Powershell command to check if the data type of variable is integer, if it has characters it should respond with a message "Enter Only number"

$
0
0
[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


Viewing all articles
Browse latest Browse all 120

Trending Articles