Is there a way to open a CMD window with a running command through Powershell? - powershell

I know it is possible to use a batch file, but due to a suggestion I switched a lot of my script over to PowerShell. The problem I ran into is that PowerShell is still missing some commands from CMD and has lower permissions when run as an Admin. Below is the current line I have been using.
powershell -Command "Start-Process 'cmd' -Verb RunAs -ArgumentList 'del /s "C:\Users\*.mp3"'"
I ran it in both 5.1 and 7.
It works with a simple command like opening the calculator or sending a ping, but I can't get the del command to work. The goal is to open a CMD window which will then delete all mp3 files. I know there are probably better ways to do this, but I more so want to know if it's possible than efficient. Thank you for your time!

This works somewhat
Start-Process cmd "/c del /S C:\Users\*.mp3"

Related

Powershell ISE breaks when using CMD /C Pause

I'm newer to PowerShell, transitioning from batch, so forgive me if I make a stupid mistake. I really like using Powershell ISE. But with the current script I'm trying to run, I use the cmd /c pause | Out-Nul command and it breaks ISE by not allowing me to continue any further.
I was trying for a long time to find some way to pause but not show output from the command and I found the cmd /c pause command. I can run it fine in a normal PowerShell prompt but ISE just isn't having it.
Anyone have any ideas why this happens or a better alternative to cmd /c pause Out-Nul? Thanks and any advice is more than welcome!
Powershell ISE doesn't redirect STDIN (which pause needs).
Shelling out to cmd for the pause command is unneeded.
See this post for more info on the ISE not being able to take stdin. You won't find your specific issue but the problem is the EXACT same problem.
On that page, you will also find a better/native way to do "pause" from powershell...
(aka [System.Console]::ReadKey($false) )

How to extract exe file without installing it, using powershell?

I am trying to extract one .exe file without installing it. The way to do in CMD is
C:\Users\ramadeviA\Downloads\Setup.exe /a
But I want to know how to execute this in powershell. Can anybody help me.
I tried this one but it doesn't work for me
$CMDCOMMAND = "C:\Users\ramadeviA\Downloads\Setip.exe /a"
Start-Process $CMDCOMMAND
Perhaps...
start-process C:\Users\ramadeviA.WINMAGIC\Downloads\Setip.exe -Argumentlist "/a"
that should be it

How to open Powershell Console Window from Powershell

I am writing a script to use multiple plink (PuTTY) sessions as a Windows version of clusterssh. I am stuck however because I want to open multiple Powershell windows from powershell. When I type the command for powershell, it opens a new session. This is similar to typing bash in bash. I want multiple physical windows opening.
I tried -windowstyle as well as the other args to no avail. I was wondering if there is a way you know of. I really appreciate your help. I looked and didn't find anything already here. Thanks for your time.
This will open a new window.
Either:
start-process powershell
Or:
start powershell
if you are trying to open a new window and launch a new script:
start powershell {.\scriptInNewPSWindow.ps1}
This will do it:
Invoke-Item C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
This works for me:
$argList = "-file `"$Location\script.ps1`""
Start-Process powershell -argumentlist $argList
(The backticks are necessary. This can be copied outright.) Variables can be used in the "-file" parameter (such as one set at the beginning of the script to reflect the location of the file) and spaces can appear in the variable due to the backticks.
Edited to use a two-line solution (the "$argList" variable) because PowerShell can mangle things otherwise.
To start Powershell 6 from a PS console start pwsh might do the trick.
It starts in the same folder.
(I haven't delved into it but I guess PS6's pwsh.exe has to be in the path for it to work.)

PowerShell: Redirect output of a command line tool to the Host

I am trying to invoke a command-line .exe tool (x264 to convert some videos) and print its output in PowerShell host.
There are a lot of parameters that need to be passed to the x264. So far I couldn't run it with the Invoke-Item cmdlet so I tried
[diagnostics.process]::start($com, $args).WaitForExit()
This works fine but it opens the old cmd window to show the output. Just out of curiosity I was wondering how can I show the output in the host.
I might be completely off, no PowerShell guru, but can't you just run the following?
$args = #("list", "of", "args", "here")
& x264.exe $args
When the cmd window opens, does it show the output? If so, maybe this can help.
Start-Process c:\x264.exe -ArgumentList $args -Wait -NoNewWindow

PowerShell and executable

Every time I run an application (.exe) in PowerShell, instead of executing it as it does with scripts, the program gets run in Command Prompt.
Invoke-Item MyProgram.exe
I thought PowerShell was supposed to replace the Command Prompt but instead PowerShell opens Command Prompt which then runs the program. Is there some way I can get PowerShell to completely replace the Command Prompt?
I thought PowerShell was supposed to replace the Command Prompt
It is, so why don't you just do MyProgram.exe
Your question is pretty vague, and in short, it will depend on the program because Invoke-Item uses the Windows default file association stuff by default.
I'm betting that using & MyProgram.exe instead of Invoke-Item MyProgram.exe will work though.
Did you try Start-Process Program.exe -NoNewWindow
I got the answer from another question:
Start-Process .\MyProgram.exe -NoNewWindow -Wait