![](/img/trans.png)
[英]PowerShell works only when running in a console and not as a PS1 executable file
[英]GetHostAddress not working when running ps1 files but works in powershell
我正在嘗試運行以下命令來獲取主機名的IP,該主機是虛擬機。
[System.Net.DNS]::GetHostAddresses("virtualservername")
在Powershell控制台中運行此命令,我得到的地址很好,但是當我通過從ps1文件調用命令來運行它時,該地址就可以了。 我收到錯誤消息“未知此類主機”
如果您直接調用[System.Net.DNS]::GetHostAddresses("hostname")
而不是將其分配給變量,請嘗試將其包含在$()結構內,然后嘗試。
$([System.Net.DNS]::GetHostAddresses("hostname"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.