Powershell with a predefined command?

I have made a button

@admin
powershell

but would like it to start using a predefined command, which would be

DISM /Online /Get-FeatureInfo /FeatureName:Recall

I tried just adding that command, but the window just closes. Maybe there is a trick? I am posting it here, because it's mainly about the Powershell syntax.

You probably just need to add a line with pause or @leavedoswindowopen to see the results.

BTW: DISM will run from a DOS prompt as well, no need for PS.

1 Like

dism is not a powershell command..

1 Like

Yeah, thanks, i will maybe try that. But i believe it would havo to run elevated.

Edit, none of that works. Looks like i need to keep pasting it from my clipboard.

But it works in Powershell. :thinking:
Maybe they included some of the old cmd shell commands?

It's not a DOS or PS command, it's a command-line utility (dism.exe).

It works anyway. See under 'check recall status'.

Here's the result from that command

PowerShell.exe /? will tell you the arguments you can use to run PowerShell.

They include these, which should let you do what you need:

-NoExit
    Does not exit after running startup commands.
-Command
    Executes the specified commands (and any parameters) as though they were
    typed at the Windows PowerShell command prompt, and then exits, unless
    NoExit is specified. The value of Command can be "-", a string. or a
    script block.

    If the value of Command is "-", the command text is read from standard
    input.

    If the value of Command is a script block, the script block must be enclosed
    in braces ({}). You can specify a script block only when running PowerShell.exe
    in Windows PowerShell. The results of the script block are returned to the
    parent shell as deserialized XML objects, not live objects.

    If the value of Command is a string, Command must be the last parameter
    in the command , because any characters typed after the command are
    interpreted as the command arguments.

    To write a string that runs a Windows PowerShell command, use the format:
        "& {<command>}"
    where the quotation marks indicate a string and the invoke operator (&)
    causes the command to be executed.
1 Like

Yes, -NoExit at the beginning of the command line did the trick. Thanks to all!

In powershell you can run regular executables as well of course, just like you can run "notepad.exe" in powershell or in a regular command prompt (cmd.exe). So, that's why running "dism.exe" works, it's a regular executable file somewhere in your PATH, but it's not related to powershell in any specific way.

This works, as you found out..
powershell -noexit -command dism ..

..but you probably get the same result (terminal window staying open) if you use an "MS-DOS Batch Function" type button and this code:

@leavedoswindowopen
dism ..

image

For more tweaks and disabling some more unwanted Windows Features, I think the Chris Titus WinUtil is worth mentioning here. It has a ton of options and convenience-clicks..

Make sure the window is big enough to see all the options or use of the scroll bar to the right, which can easily be overlooked, it is a bit too dark and slim for my taste to be recognized easily.

Thanks, i could test that too. I need it to check if that function stays disabled after Win updates. Not sure about how to use WinUtil, i only found that ps1 script, no installer.. Ok, got it.