无法在Powershell中ping变量?

时间:2017-11-15 16:25:23

标签: powershell

我仍然非常喜欢使用PowerShell编写脚本但是我无法理解为什么要使用以下内容。而且我相信为什么我无法设置一些变量。

PS C:\WINDOWS\system32> $s
PC04PA71


PS C:\WINDOWS\system32> ping $s

Ping request could not find host PC04PA71
. Please check the name and try again.

PS C:\WINDOWS\system32> ping PC04PA71

Pinging PC04PA71.xxx.xxx.xxx.com [xxx.xxx.190.160] with 32 bytes of data:
Reply from xxx.xxx.190.160: bytes=32 time=68ms TTL=124

1 个答案:

答案 0 :(得分:1)

尝试修剪你的变量,不要忘记你可以在PowerShell中使用Test-Connection

Test-Connection $s.Trim()