0

I am using PowerShell to get the File Version of a file

C:\WINDOWS\system32>powershell (Get-Command C:\Users\lafarnum\Downloads\aniteloggingclientapi.dll).FileVersionInfo.FileVersion 1.12.0.4

The output file version is 1.12.0.4. I wanted to pipe this file version into a DOS CMD variable like a normal assignment but the issue is it is simply assigning the PowerShell command string , not the output of the PowerShell command

C:\WINDOWS\system32>set pfpathset=powershell (Get-Command C:\Users\lafarnum\Downloads\aniteloggingclientapi.dll).FileVersionInfo.FileVersion

C:\WINDOWS\system32>echo %pdpathset% %pdpathset%

C:\WINDOWS\system32>echo %pfpathset% powershell (Get-Command C:\Users\lafarnum\Downloads\aniteloggingclientapi.dll).FileVersionInfo.FileVersion

C:\WINDOWS\system32>

So the PS command output does not seem to be directly directed to the CMD STDOUT output? So do I have to pipe the output of the PS command into another string variable and then assign that variable to my pfpathset variable? or do I have to use a ps script to do this?

Sorry if this is a basic question but I am a powershell novice, so any help given would be appreciated.

Thanking you in anticipation

Sproggit
  • 71
  • 1
  • 7
  • just go for PS all the way. There is no reason I can think of why you should mix Powershell and CMD in 2021 to be honest. – bluuf Jul 28 '21 at 11:26
  • What problem are you solving? Are you asking how to get a file's version number metadata in a cmd.exe shell script (batch file)? I am also wondering the same as the previous commenter: Why not dispense with cmd.exe altogether and write the whole script in PowerShell? – Bill_Stewart Jul 28 '21 at 16:00

1 Answers1

0

Similar to Assign command output to variable in batch file. You need the double quotes because of the parentheses.

In a .bat file put %%i instead of %i.

for /f %i in ('powershell "(Get-Command notepad).FileVersionInfo.FileVersion"') do set output=%i

echo %output%
10.0.19041.1
js2010
  • 23,033
  • 6
  • 64
  • 66