Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 是否将powershell命令的输出保存在变量中并在批处理脚本中使用?_Windows_Batch File_Powershell_Fqdn - Fatal编程技术网

Windows 是否将powershell命令的输出保存在变量中并在批处理脚本中使用?

Windows 是否将powershell命令的输出保存在变量中并在批处理脚本中使用?,windows,batch-file,powershell,fqdn,Windows,Batch File,Powershell,Fqdn,我试图做的是保存powershell命令的输出(从批处理脚本运行)并在批处理脚本中使用它 你能告诉我怎么办吗 power shell comand是: [System.Net.Dns]::GetHostByName((hostname)).HostName 我想在批处理脚本中使用输出 附笔。 如果我能从cmd而不是powershell获得完整的计算机名/主机名/完全限定域名(FQDN),那就更好了。但是计算机全名不是ComputerName和UserDNSDomain变量的串联。您可以使用执行

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

你能告诉我怎么办吗

power shell comand是:

[System.Net.Dns]::GetHostByName((hostname)).HostName
我想在批处理脚本中使用输出

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

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

for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i
echo %return%
for /f "tokens=1*" %%a in ('nslookup hostname ^| findstr /i "name"') do set return=%%b
echo Hello '%return%'

从powershell,$env:computername'可以为您获取计算机名,如果您的PS是这个意思的话。@thufir我知道赏金要求100%的powershell解决方案,但我没有看到要转换的批处理代码。@thufir:我不明白。问题是如何从批处理中使用100%powershell命令,因此问题本身应该是您正在寻找的答案。如果不是,请澄清,或者更好地问一个新问题。