I'm not sure what is the best approach for asking these question, so I'm putting them all together here. After some googling these questions didn't have an obvious answer.
1) In Powershell ISE is there a way to change the "run selection" quick-key/hot-key so that it's something other than the default (which is F8)?
2) For that matter, is there a way to add quick-key bindings without adding a menu?
3) Can one add key cords to the ISE like in Visual Studio (Ctrl-d, Ctrl-h) for example.
I don't think you can change, but you can add another key to do the same:
function invoke-selection
{
iex $psISe.CurrentFile.Editor.SelectedText
}
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Run selection",{invoke-selection},'f7')
Add the above to your Powershell ISE profile - $profile from ISE
Simple answer in no.
Unfortunately the ISE is a very basic editor and doesn't provide much in the way of customisation.
This might change when the ISE for PSv3.0 is released.
In the mean time this post has a list of PowerShell ISEs that you might want to try:
https://stackoverflow.com/questions/171514/best-ide-for-powershell
regards
Arcass
Related
MATLAB has a feature to allow users to introduce a command in the script/function called keyboard and have the code stop there with a console/command prompt that gives direct access to the interpreter and the variable space. MATLAB keyboard() command docs
Is there something similar in Powershell? I don't want to deal with Powershell ISE as I don't like it's syntax highlighting (doesn't highlight all occurrences of selected phrase like Notepad++ does) and the macros is a lot weaker than what the plain Powershell console itself (like lacking F8 for recalling).
Stepping with a debugger is not quite as useful when you need to explore complex object structures and try a few things out with the current variable states, instead of just reading what the variables and values are in a docked window. It's much easier to work with the state of mind of the interpreted language at any point by interacting with it instead of ploughing through stack and trace information.
In both Powershell ISE and VSCode, you can read or update the same variables in your session from the terminal window at the bottom, even during debugging.
Been searching around and not able to find an answer to whether or not powershell has a hard breakpoint solution. Something like javascript debugger; and python breakpoint() and vb Stop.
Instead i have to author dummy lines inside if statements that i can assign soft breakpoints to.
if ($item.Value -eq "some large iteration case i need to debug through") {
$i = "using to enable soft breakpoint on specific case for debugging purposes as powershell doesn't appear to have have hard breakpoint expression"
}
You can use Set-PSBreakpoint and enable/disable-psbreakpoint
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-psbreakpoint?view=powershell-7
https://ss64.com/ps/enable-psbreakpoint.html
Download the PowerShell ISE, or use Visual Studio with the PowerShell extension.
I'm trying to use group policy to replace the default windows Powershell shortcut with one that automatically checks the advanced option for the default shortcut: 'Run as Administrator' that can be found when editing the properties of the shortcut. Shown as followed,
However in group policy, the settings for shortcuts are limited. You may provide arguments, but that is all. and I suspect that it is an argument in the default shortcut that allows it to run as Administrator because besides giving arguments and a starting directory to a shell there is nothing else to it besides the shell. (See picture)
Unfortunately, windows does not show what arguments are provided to the default shortcut that allow it run as administrator.
So if someone could tell me what arguments the shortcut has that allow it to do 'Run as Administrator' I would greatly appreciate it. Thank you.
There is unsupported usy-at-your-own-risk method - setting byte #21 to 34
There is also more argumented method doing this ( I think it is better, because it takes into account old binary value )
Alternatively, to use from PowerShell you should find a wrapper around WinApi methods to set SLDF_RUNAS_USER flag for shortcut.
I think, you should test second method to use in PowerShell
There is no native way doing this from any .net-based language.
Documentation: MS-SHLLINK
I am using the same, longer command line with some arguments every day and it would be nice, if there were some possibility to make some shortcut for it. Is there any?
Learn aliases. Of course they depends of shell you're using. Doskey for cmd, alias for powershell or tcc, and so on.
Also. ConEmu has GuiMacro feature. You may set up user hotkeys with print function.
I have a feeling that this is a very simple fix, but whenever I try to paste into PowerShell using right-click, it automatically executes whatever it is I am trying to paste. The function is finding a computer name based on an input using AD and then copies the computer name to use in other functions. Here is the code for only the part that does the copying:
$strComputer = $output.Name
$strComputer | clip | Out-Null
So when I right-click to paste, it executes whatever $strComputer equals and obviously throws an error. Thanks!
The problem with pasting something into PowerShell (and clip.exe is very good example) is the fact, that any newline (and clip.exe used like that will add newline at the end) will trigger same reaction that you pressing enter would.
There are at least two ways around it:
paste without newlines (e.g. use [System.Windows.Clipboard]::SetText($output.Name))
if you are on v3 - use PSReadLine module and CTRL+V
For the first one - be sure to run Add-Type -AssemblyName PresentationCore first - this assembly is loaded by default only in PowerShell ISE. If you are on v3+ though I would really recommend to give PSReadLine a try.
I've found an easy solution, that doesn't require any Powershell modifications.
Steps:
Type if ($true) { into the terminal.
Paste in the code-block. Because you started an if-block, but didn't provide an end-bracket for it, Powershell interprets the code-block as incomplete, and so awaits the end-bracket before running anything.
Now you can use the arrow keys to edit the code block however you want.
When you're done with your edits, add the missing } to the very end, then press enter to execute it.
Alternatively you can use the ISE, where you can paste into the Script Pane (the top half), and edit until it appears as desired, and run when you want to.