10

我要做的是保存powershell命令的输出(从批处理脚本运行)并在批处理脚本中使用它。

你能告诉我该怎么做吗?

电源外壳命令是:

[System.Net.Dns]::GetHostByName((hostname)).HostName

我想在批处理脚本中使用输出。

附言

如果我可以从 cmd 而不是从 powershell 获取完整的计算机名/主机名/完全限定域名 (FQDN),那就更好了。但完整的计算机名称不是 ComputerName 和 UserDNSDomain 变量的串联。

4

2 回答 2

11
for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i
echo %return%
于 2014-08-14T10:13:34.157 回答
3

您可以使用nslookup相同的 DNS 搜索批量执行此操作:

for /f "tokens=1*" %%a in ('nslookup hostname ^| findstr /i "name"') do set return=%%b
echo Hello '%return%'
于 2018-02-21T19:41:04.010 回答