Save the output of a powershell command in a variable and use it in batch script?

后端 未结 2 535
一生所求
一生所求 2021-01-04 14:04

What I am trying to do is to save the output of a powershell command (run from a batch script) and use it in the batch script.

Can you please advise me what to do?

相关标签:
2条回答
  • 2021-01-04 14:39
    for /f "tokens=*" %%i in ('powershell /command "[System.Net.Dns]::GetHostByName((hostname)).HostName"') do set return=%%i
    echo %return%
    
    0 讨论(0)
  • 2021-01-04 14:44

    You can do this in batch using nslookup which does the same DNS-search:

    for /f "tokens=1*" %%a in ('nslookup hostname ^| findstr /i "name"') do set return=%%b
    echo Hello '%return%'
    
    0 讨论(0)
提交回复
热议问题