Page 1 of 1

Need batch script version of this complex command

Posted: 30 Sep 2022 00:38
by tobwz
At the bottom of this posting you can see a complex command to let Windows 10 show a couple of version+build info about the current WinOS.

It works when directly entered at the command prompt.

But when I put it into a batch script a couple of errors occur.

What do I have to change to be able to run it from inside a batch script?

Code: Select all

@echo off & echo. & for /f "usebackq delims=" %i in (`ver`) do (echo  %i:) & echo. & PowerShell Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' ^| Format-List ^
     @{L=' Current Major Version Number';E={;if([string]::IsNullOrWhiteSpace($_.CurrentMajorVersionNumber)) {'N/A'} else {$_.CurrentMajorVersionNumber}}}, ^
     @{L=' Current Minor Version Number';E={;if([string]::IsNullOrWhiteSpace($_.CurrentMinorVersionNumber)) {'N/A'} else {$_.CurrentMinorVersionNumber}}}, ^
     @{L=' Current Build'               ;E={;if([string]::IsNullOrWhiteSpace($_.CurrentBuild))              {'N/A'} else {$_.CurrentBuild}}}, ^
     @{L=' Current Build Number'        ;E={;if([string]::IsNullOrWhiteSpace($_.CurrentBuildNumber))        {'N/A'} else {$_.CurrentBuildNumber}}}, ^
     @{L=' UBR [Update Build Revision]' ;E={;if([string]::IsNullOrWhiteSpace($_.UBR))                       {'N/A'} else {$_.UBR}}}, ^
     @{L=' Base Build Revision Number'  ;E={;if([string]::IsNullOrWhiteSpace($_.BaseBuildRevisionNumber))   {'N/A'} else {$_.BaseBuildRevisionNumber}}}, ^
     @{L=' Build Branch'                ;E={;if([string]::IsNullOrWhiteSpace($_.BuildBranch))               {'N/A'} else {$_.BuildBranch}}}, ^
     @{L=' Build Lab'                   ;E={;if([string]::IsNullOrWhiteSpace($_.BuildLab))                  {'N/A'} else {$_.BuildLab}}}, ^
     @{L=' Build Lab Version [Extended]';E={;if([string]::IsNullOrWhiteSpace($_.BuildLabEx))                {'N/A'} else {$_.BuildLabEx}}}, ^
     @{L=' Build GUID'                  ;E={;if([string]::IsNullOrWhiteSpace($_.BuildGUID))                 {'N/A'} else {$_.BuildGUID}}} ^| ^
Out-String -Width 1000 -Stream ^| Where {$_.Trim().Length -gt 0} & echo. & pause & Exit

Re: Need batch script version of this complex command

Posted: 30 Sep 2022 00:57
by aGerman
In Batch code you need to double the percent signs of FOR variables. Replace the two occurrences of %i with %%i and try again.

Steffen

Re: Need batch script version of this complex command

Posted: 30 Sep 2022 06:17
by tobwz
works.
Thank you