Running a Powershell command from batch. Not using .PS1

Hello Everyone,

I want to run the blow command from a batch file which will give me a list of installed applications on the machine:

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > C:\temp\PS.txt

The only way i am able to find is. Saving this command in a PS1 file and then calling this file from the batch file.

Is there any way i can execute this command directly from the batch file not calling the .PS1 script?

Thank you in advance. :)

Parents
  • Here is a wrapper template which is a cmd file that contains batch code as the first line, and all subsequent lines as powershell commands. The first line begins with "# 2>NUL" and ends with "EXIT /B"

    # 2>NUL & @cls & PUSHD "%~dp0" & "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -nol -nop -ep bypass "[IO.File]::ReadAllText('%~f0')|iex" & POPD & EXIT /B

    write-host "Hello, from inside Powershell version $($psversiontable.psversion.major)" -foreground cyan

Reply
  • Here is a wrapper template which is a cmd file that contains batch code as the first line, and all subsequent lines as powershell commands. The first line begins with "# 2>NUL" and ends with "EXIT /B"

    # 2>NUL & @cls & PUSHD "%~dp0" & "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -nol -nop -ep bypass "[IO.File]::ReadAllText('%~f0')|iex" & POPD & EXIT /B

    write-host "Hello, from inside Powershell version $($psversiontable.psversion.major)" -foreground cyan

Children
No Data