Running PowerShell Script in real PowerShell Window - powershell

When I type this command in a classic windows command promt (black, small, not full resizable, small pre defined scroll buffer)
powershell myScript.ps1
The script will be executed in the classic command prompt window.
But I want to have a real power shell window (blue background, bigger, full resizable, "endless" scolling).
How to do this?

if i understand you correctly, you just want to have a powshell window instead of a cmd one. open a powershell window by typing powershell in start->run
you can just ./myScript.ps1 to execute your script, assuming that your execution policy is set up properly already.

Related

Why is the termination behaviour of vscode different with other GUI program (WinMerge) when invoking from PowerShell?

In Windows PowerShell 5.1, after run & code ., a VSCode window opens, and the control returns back to PowerShell immediately. After the PowerShell exists, the VSCode will not be terminated.
On the other hand, when invoke other external program, such as WinMerge, after run & WinMergeU, a WinMerge window opens, and the control does not return back to PowerShell until WinMerge window is closed. And If PowerShell exists, WinMerge will be terminated.
Why the behaviour is different?
the difference is what is actuall happening:
when you run the command code, you are not really running code.exe. its starting a cmd script that spawns a new code.exe process with whatever arguments you passed it.
to see what a command actually executes, use the command get-command 'yourcommand', or with code get-command code.
this will show the follwing source: C:\Users\{username}\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd.
Opening up this will show you:
#echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" --ms-enable-electron-run-as-node %*
endlocal
so this means that in both cases you are waiting for execution to end, but for code its a code.cmd script and not actually code.exe.
If you want to start new processes and don't wait for them, you can use the command start-process winmergeu

How do i hide file path information in VS-Code Terminal

I see this unnecessary file path information whenever I execute a program in the terminal section.
Is there a way to hide that file path?
This is not so much VSCode terminal related, rather it is more shell related (see What's the difference between Terminal, Console, Shell, and Command Line). Your VScode's terminal is running a shell internally, but a terminal is not much more than a display window that calls a shell's functions. So, in order to edit the prompt (which comes from the shell), we have to edit your shell config.
From your screenshot, it looks like the particular shell you're running is Powershell. Powershell has its own prompt that it generates each time before you run a command. It does so by calling the prompt() function (you can read more about it at Microsoft Docs).
Therefore, if you just want an empty prompt, then all you have to do is create an empty prompt function and add it to your powershell profile.
From your terminal, open your powershell profile file using VSCode (or any text editor)
# $profile is a variable in powershell
# that holds path of the powershell config
code $profile
Then add an empty prompt function into the profile
function prompt { }
Save the file and reopen another powershell instance in your VSCode terminal, and now it should look like this
PS>
If you're interested in further customizing this prompt, I would highly recommend looking into starship, a cross-platform shell prompt that can be used inside powershell. By default it's an even simpler arrow
❯
It only displays the most relevant paths, and can be customized to a much greater extent than the powershell prompt.

Is there a way to allow Powershell to "buffer" commands?

When using the CMD prompt, you can "type ahead" commands and when the current operation is finished, the command will be issued to the CMD prompt.
When you execute the following in CMD, foo will run, then bar will run. However in PowerShell, it will ignore bar.exe<ENTER> because foo is running. Is there a way around this? It's pretty frustrating to have to wait for a command to finish before executing a subsequent command.
foo.exe<ENTER> (takes 60 secs)
bar.exe<ENTER>
It depends on the host. In the console host (powershell.exe) it works the same as cmd (the way you want it to). In ISE (powershell_ise.exe) it does not.
You won't be able to change this behavior.
Your workaround then is to use the console host instead of ISE for interactively typing commands.
If you know you're going to run both, write foo.exe; bar.exe
Or write them both in the ISE edit window, and press F5 to run.

Change PowerShell title to currently running command

I'd like to change the title of my powershell window to the currently running command. For example, I often have several PS windows open, each one running a continuous ping to a different host, and it would be handy to show which host is which in the title.
I can change the title after a command has been run using a function in the PS $profile based on Roman's excellent answer here. However, that function only runs when the command has completed and I'm back to the "PS C:\" prompt.
Basically, I'm trying to make it work the same way cmd.exe works out of the box:
Default PowerShell Title
Default Cmd Title

How do I make Powershell run VBS files in the console without affecting double click behaviour?

On my PC, VBS files are set (via the file association entries in the registry) to run using WScript. This is what I want, so that I can double click on a VBS file and not have a console window open. However, when I am using the Powershell command line, I would like VBS scripts to run using CScript (i.e., using "cscript /nologo myfile.vbs"). Is there a way to make Powershell do this, without affecting the double-click behaviour?
For single scripts, I could write a function for each one (function foo { cscript /nologo foo.vbs $args }) but that doesn't scale at all. I'm thinking of something like Take Command's "executable extensions" feature, that lets you set a specific action for a file extension (set .vbs=cscript /nologo).
I have the same problem for Python scripts, where again the default action doesn't do what I want (for some reason, it opens a second console window, rather than displaying output in the Powershell console) so a VBS-specific answer will only give me part of what I want :-(
Thanks,
Paul
The easiest thing i can think of is, to set an environment variable whenever you start Power Shell (does it have an autoexec feature?) let's call it "InPowerShell" and give it the value "YES".
Then create a .bat file like this:
if %InPowerShell%==YES (
cscript /nologo #*
) else (
wscript #*
)
Set all vbs files to open with this bat file. This way whenever you double click it it will be opened with wscript, and inside powershell will open with cscript.
(Note: I didn't test this)