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