Answer the question
In order to leave comments, you need to log in
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
: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
Answer the question
In order to leave comments, you need to log in
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.
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
)
for /f
read the file. for /?
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 questionAsk a Question
731 491 924 answers to any question