C
C
chief2021-02-01 12:15:52
cmd/bat
chief, 2021-02-01 12:15:52

How to correctly call another bat in a .bat file and pass a variable?

Good day everyone. Help :)
Task: Update a PC in the domain to the latest version of Windows
Problem: I can not correctly compose batch files for convenient work
What you need: A batch file of the following content-:
- Enter the name of the PC: (here I enter the name of the PC)
- psexec = Displays information about the entered PC (Locale, dozens build, Windows version, bit depth, free space on drive C)
- Action selection menu (which launches the following scripts in a new window):
-1. Upload and update RU x64 (installw10ru64.bat)
--2. Upload and update UA x64 (installw10ua64.bat)
--3. Upload and update RU x32 (installw10ru86.bat)
- return to start (enter PC name). //to be able to run another update in a new window.

Ideally, it would be cool to make the script itself select the desired script based on the Windows version and bitness, but I could not drive the psexec output into a variable.

My work:
Script 1 - Checking system information

@echo off
:start
set /P id=Enter PC Name:
psexec \\%id% powershell Get-UICulture; write-host "Windows 10 Build:" (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ReleaseId; write-host "Windows Architrcture:" (Get-WmiObject win32_operatingsystem).osarchitecture; cmd /c ver;  Get-WmiObject Win32_LogicalDisk
pause
goto start


Script 2 - Copying the distribution kit from the balls to the C drive and running a silent update // example of a batch file installw10ru64.bat
:start
set /P id=Enter PC Name : 
robocopy /E /R:1 /W:1 "\\192.168.5.5\w10ru64" "\\%id%\c$\w10ru64"
psexec \\%id% c:\w10ru\setup.exe /auto upgrade /quiet /showoobe none /priority low /dynamicupdate disable
}
pause
goto start


Dear command line gurus, please help me to make the script :)
- If possible - in one file that will launch other windows with the same name with the given script for copying the desired folder and launching the update.
- We need to check the existence of the distribution folder on the target PC (also failed to transfer to a variable). Folders on drive C: (w10ru64, w10ua64, w10ru86).

Thank you very much in advance

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Dmitriev, 2021-02-01
@SignFinder

Use Powershell and WinRM.
To select actions within one script, you can use if else, then you will not need to exit it to other scripts.
The launch of the installer in Powershell can be implemented by creating a Scheduled Task on each specific machine.

R
res2001, 2021-02-01
@res2001

How much did you understand the whole problem with you - to process the output of psexec?
There is a construct for this. for /f
For example:

for /f "tokens=* delims=" %%a in ('psexec ... ') do ( 
  echo %%a
)

It is also possible to redirect the output of psexec to a file, and then to for /fread the file.
For reference:for /?

A
Armenian Radio, 2021-02-01
@gbg

Use Python or bash. Seriously, to write something longer than five lines on batch files is to take out the brain with debugging.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question