Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 to run and since I don't really know how to script with PowerShell.

Here is the command I'm trying to use to start with:

Get-AppLockerFileInformation -Directory <folderpath> -Recurse -FileType <type>

I don't really want to create a script for this as it would be much easier if I can just run one or two commands from a batch file with the rest of the stuff.

EDIT: Here is what I've tried so far.

1)

powershell -Command "Get-AppLockerFileInformation....."
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....

2)

powershell -Command {Get-AppLockerFileInformation.....}

No error with this way but I don't get anything back. If I use the Set-AppLockerPolicy... nothing happens.

3)

powershell -Command "{Get-AppLockerFileInformation.....}"
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....

4)

powershell -Command "& {Get-AppLockerFileInformation.....}"
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....

5)

powershell "& {Get-AppLockerFileInformation.....}"
Error: The term 'Get-AppLockerFileInformation is not recognized as the name of a cmdlet, function, script file, or operable program....

6)

powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command {Get-AppLockerFileInformation....}

No error but nothing happens.

7)

powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "Get-AppLockerFileInformation...."

No error but nothing happens.

share|improve this question
1  
On one hand you say "I don't really want to create a script" and on the other hand you say "if I can just run one or two commands from a batch file". So: which is it??? –  djangofan Aug 27 '13 at 0:19
 
I should clarify, I don't want to create a powershell script. –  Chef Pharaoh Aug 29 '13 at 16:07
 
And Get-AppLockerFileInformation works fine for you when running from a new fresh and clean powershell prompt? What OS? (tested Get-App.. in Win7 and there is no such cmdlet in that case so get the same error message) –  NiKiZe Aug 29 '13 at 20:08
 
I first use the Import-Module AppLocker command to load the library. I'm using Windows Embedded 7. Maybe I need to combine the 2 calls, import the library then run the command...?? –  Chef Pharaoh Aug 29 '13 at 22:38
 
stackoverflow.com/a/19111810 may be relevant for you. It is about how to combine .cmd and .ps1 into 1 file (.cmd). –  robert4 Oct 1 '13 at 9:23
show 1 more comment

2 Answers

Run it on a single command line like so:

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile 
  -WindowStyle Hidden -Command "Get-AppLockerFileInformation -Directory <folderpath> 
  -Recurse -FileType <type>"
share|improve this answer
 
As soon as I get a chance I will try this out. There seems to be a lot of flags in there though, would it be the same if I want to use Set-AppLockerPolicy and New-AppLockerPolicy? –  Chef Pharaoh Aug 28 '13 at 22:37
 
This didn't work, not to mention the <code>-WindowStyle</code> flag closes my command prompt... Also, I don't need the <code>ExecutionPolicy</code> flag since I'm using the command line directly. –  Chef Pharaoh Aug 29 '13 at 15:38
 
Yes, some of the options are probably unnecessary. Just tweak depending on what you need. More info here: zduck.com/2012/powershell-batch-files-exit-codes –  djangofan Aug 29 '13 at 17:33
add comment

Maybe powershell -Command "Get-AppLockerFileInformation....."

Take a look at powershell /?

share|improve this answer
 
That's what I've been trying but I don't seem to be getting the syntax quite right or something. When I run the command directly from the powershell it works fine though... –  Chef Pharaoh Aug 26 '13 at 23:57
 
Ok, Do you get any error or something else? Please edit your question and provide more information. What have you tried and what does not work etc. –  NiKiZe Aug 27 '13 at 0:09
 
Please see my edit above. –  Chef Pharaoh Aug 29 '13 at 15:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.