Run PowerShell command from command prompt (no ps1 script)

前端 未结 4 1543
花落未央
花落未央 2020-12-12 22:17

I\'m looking for a way to run just a couple PowerShell commands from the command prompt. I don\'t want to create a script for this since it\'s just a couple commands I need

4条回答
  •  北海茫月
    2020-12-12 23:12

    Here is the only answer that managed to work for my problem, got it figured out with the help of this webpage (nice reference).

    powershell -command "& {&'some-command' someParam}"
    

    Also, here is a neat way to do multiple commands:

    powershell -command "& {&'some-command' someParam}"; "& {&'some-command' -SpecificArg someParam}"
    

    For example, this is how I ran my 2 commands:

    powershell -command "& {&'Import-Module' AppLocker}"; "& {&'Set-AppLockerPolicy' -XmlPolicy myXmlFilePath.xml}"
    

提交回复
热议问题