r/scripting • u/famikon • Aug 22 '19
[Batch] How to take output of a command and insert it into a command string?
edit: I figured it out!
I've built this script to display current hostname, ask for input for a new hostname, and rename the computer.
@echo off
for /f %%i in ('C:\Windows\System32\hostname.exe') do set hn1=%%i
echo Current Hostname: %hn1%
set /p hn2="Enter New Hostname: "
WMIC computersystem where caption='%hn1%' rename '%hn2%'You could also add this to trigger an instant computer restart
shutdown /r -t 03
4
Upvotes
2
u/[deleted] Aug 22 '19
Check this out .
https://stackoverflow.com/questions/2323292/assign-output-of-a-program-to-a-variable-using-a-ms-batch-file
Essentially you want to output the results to a variable, and call it later when you need it.
0
u/[deleted] Aug 23 '19
[deleted] — view deleted comment