How to execute Powershell command from CommandPrompt? One line!


  1. Posts : 244
    win7pro 64bit
       #1

    How to execute Powershell command from CommandPrompt? One line!


    I want to execute a PowerShell command from Command Prompt.
    This should be done by entering ONE command!

    I DO NOT want to start PowerShell first and then enter the PowerShell command.

    Instead I want to enter something like

    powershell.exe -command "......."

    How does that work in detail on Win7?

    Peter
      My Computer


  2. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #2

    Hi pstein,

    pstein said:
    I want to execute a PowerShell command from Command Prompt.
    This should be done by entering ONE command!

    I DO NOT want to start PowerShell first and then enter the PowerShell command.

    Instead I want to enter something like

    powershell.exe -command "......."

    How does that work in detail on Win7?
    What do you want the command to produce?
      My Computer


  3. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #3

    Hi pstein,

    If you wanted to get the bit-type of your OS for example, you could use this in the cmd prompt . . .

    Code:
    Powershell -Command (Get-WmiObject Win32_OperatingSystem).OSArchitecture
    You could also use that in a batch script!

    I hope this helps!
      My Computer


  4. Posts : 244
    win7pro 64bit
    Thread Starter
       #4

    Why does

    Powershell -Command {Get-HotFix | Sort InstalledOn -Desc}

    NOT work?

    When I enter this in CmdPrompt/Batch script then the output is:

    "Input file specified two times."
      My Computer


  5. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #5

    Hi pstein, I do have a batch script that lists all the installed updates!
      My Computer


  6. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #6

    pstein said:
    Why does

    Powershell -Command {Get-HotFix | Sort InstalledOn -Desc}

    NOT work?

    When I enter this in CmdPrompt/Batch script then the output is:

    "Input file specified two times."
    See Powershell /? for explanation.

    You need to create a string that Powershell can execute, so in your case, type:

    Powershell -Command "& {Get-HotFix | Sort InstalledOn -Desc}"

    Obvious when you know how!!
      My Computer


  7. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #7

    Hi iko22,

    iko22 said:
    See Powershell /? for explanation.

    You need to create a string that Powershell can execute, so in your case, type:

    Powershell -Command "& {Get-HotFix | Sort InstalledOn -Desc}"

    Obvious when you know how!!
    You beat me to it!
      My Computer


  8. Posts : 2,798
    Windows 7 x64, Vista x64, 8.1 smartphone
       #8

    Paul Black said:
    Hi iko22,



    You beat me to it!
    Well, youve had two hours.
      My Computer


  9. Posts : 6,021
    Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
       #9

    iko22 said:
    Well, youve had two hours.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:22.
Find Us