Home > Net >  Modify powershell output
Modify powershell output

Time:08-11

I have the following script that the great community on this site helped me create. I run this as part of a batch script

powershell -Command Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' 'DisplayVersion' >> C:\ProgramData\Data_Mover\info.txt

It will write the os build to the txt file (EX: 21H2)

What I need is to add this before the 21H2:

Build :

I have looked online and similar scripts with no luck

Does anyone know how to get the requested output?

CodePudding user response:

PowerShell offers several ways to prepend Build : to the output from your Get-ItemPropertyValue call: string concatenation with , string interpolation via a double-quoted string ("..."), or use of the -f operator.

Here, is the simplest choice, as it doesn't introduce additional escaping considerations when you pass the command from cmd.exe (a batch file) via powershell.exe, the Windows PowerShell CLI:

powershell.exe -Command "'Build : '   (Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' DisplayVersion)"

Note that, for robustness, I've enclosed the entire command in "..."; for brevity, I've omitted the >> redirection.

  • Related