[英]Save the output of a powershell command in a variable and use it in batch script?
我想要做的是保存powershell命令的输出(从批处理脚本运行)并在批处理脚本中使用它。
你能告诉我该怎么办?
电源外壳命令是:
[System.Net.Dns]::GetHostByName((hostname)).HostName
我想在批处理脚本中使用输出。
如果我可以从cmd获取完整的计算机名/主机名/完全限定的域名(FQDN)而不是PowerShell,那将会更好。 但完整的计算机名称不是ComputerName和UserDNSDomain变量的串联。
for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i
echo %return%
您可以使用执行相同DNS搜索的nslookup
批量执行此操作:
for /f "tokens=1*" %%a in ('nslookup hostname ^| findstr /i "name"') do set return=%%b
echo Hello '%return%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.