Need batch script version of this complex command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tobwz
Posts: 30
Joined: 25 Feb 2022 03:21

Need batch script version of this complex command

#1 Post by tobwz » 30 Sep 2022 00:38

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need batch script version of this complex command

#2 Post by aGerman » 30 Sep 2022 00:57

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

tobwz
Posts: 30
Joined: 25 Feb 2022 03:21

Re: Need batch script version of this complex command

#3 Post by tobwz » 30 Sep 2022 06:17

works.
Thank you

Post Reply