Powershell命令检查变量的数据类型是否为整数,如果包含字符,则应使用消息“仅输入数字”进行响应]] << [

问题描述 投票:0回答:1
[int] $ name =读取主机输入知识库文章编号如果($ name -is [int]){wusa / uninstall / kb:$ name写主机“这将卸载Windows更新KB $名称”}其他{写主机“仅输入数字”}

在此PowerShell脚本中,每键入一个字符都会返回错误,而不是消息“仅输入数字”。

PS C:\ Users \ User \ Desktop>。\ Test.ps145454输入KB编号:asfs无法将值“ asfs”转换为类型“ System.Int32”。错误:“输入字符串的格式不正确。”在C:\ Users \ User \ Desktop \ Test.ps1:5 char:1+ [int] $ name =读主机输入知识库文章编号+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidArgument:(:) [],RuntimeException + FullyQualifiedErrorId:InvalidCastFromStringToInteger

这将卸载Windows更新KB0

[int] $ name =读取主机输入KB号如果($ name -is [int]){wusa / uninstall / kb:$ name写主机“这将卸载Windows更新KB $ name”}否则{写主机“仅输入数字”}在这里...

powershell powershell-3.0
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.