Open PowerShell here in background directory - powershell

I have been trying to create some registry keys to open PowerShell as you would Command Prompt in explorer by pressing Ctrl+Shift+Right Click.
I have the context key created here:
but the value I put here:
returns an error when I click Open PowerShell here
I've tried a few string values now but still with similar results. Has anyone accomplished this using the background directory key and if so how did you do it?

You will want to use %V instead of %1.
Change the Default value like so:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit "cd '%V'"

Related

Copy Command Prompt's content to clipboard

I'm looking for a solution to copy the command prompt's current content to the clipboard. I know something similar is possible by redirecting the output or using clip but I'm looking for something else. I'm looking for a command which copies the entire content of the command prompt window to the clipboard/a file anytime when it's called(not just the output of one command). It's quite easy to do manually by selecting everything and press ctrl-c but I need a command for this.
Basically it should achieve the same as doskey /history > somefile.txt but saving the output of the commands too.
Is something like this possible?
you can use simple java program , to get the entire content of the command prompt and out it into a String variable or write it to txt file

Task Scheduler | I am trying to schedule a .ps1 file but every time the scheduler runs a pop window appear "How Do you want to open this file?"

Here's a screenshot from scheduled task action settings
First of all make sure the path used for powershell is correct (best option in my opinion is to click Browse... and select the program with the dialog window instead of manually inserting the full path, if that's what you did).
In second place, change Add arguments (optional): to -File "D:\TM1 Model\Test GIIS\...\yourfilename.ps1", please note you should use double quote since the full path contains spaces; again, make sure the full file path is typed correctly.
There should be no need to insert the full path in the in the Program/script box. Most people don't even know where it is.
For all the PowerShell scripts that I run on servers I only type powershll.exe and it works.
I agree with Giacomo (Calvin?), the value in the Add Arguements box needs to be in quotes if you have spaces in the folder or file name. ie -File "C:\Batch Files\checkdisk.bat"
The -File argument is telling PowerShell the file you want powershell.exe to run.

How to convert powershell onliner to PS1

I have a powershell one liner that would like to transform on a PS1 file
This question is pretty basic but how do I convert apowershell one liner to PS1?
Thanks
There are a few steps to do this:
Open notepad.
Copy and paste the powershell script into notepad. Now if the one-liner has multiple lines using ; separate them by using enter. You can expand The for, if, while, try blocks like this:
try
{
Anything
}
You can also make the script accept args using $args automatic variable. $args[0], $args[1] .. $args[n] parameters and so on.
Select file menu and save as dialog.
Enter the name of powershell script with extension .ps1 (Example: foo.ps1).
Choose "All files" in the drop down menu.
Click save button. Here you go!

How do I prompt for a path to a directory with support for tab completion in the console?

I want to prompt the user for a directory path.
The user can enter some text like C:\Pro in command line, tap tab button and the script should autocomplete the text toC:\Programs\ on another tab it should change the text to C:\Program Files\.
So, the script should scan folders and help user to navigate between them on typing.
Important: I can't use any GUI dialogs, because I am going to use the script on Win with no GUI.
This code will not work:
New-Object System.Windows.Forms.FolderBrowserDialog
Ummm... you don't have to? PS already does that by default?
function T
{
param
(
[System.IO.FileInfo]
$P
)
$P.FullName
}
T -P # Pressing <tab> at this stage will automatically show you the first file in your working directory. That happens even if the P was of type string.

Make PowerShell suggests current folder content/items using the Tab key

I'm new to PowerShell,
I'd like to navigate through the file system by getting the current folder content suggestions instead of cmdlets by clicking the Tab key just like in the CMD.
I don't want to use the dir cmdlet, I want to walk through the different items by clicking on the Tab key.
Is that possible and how to do it ?
If you type ex. a<tab>, you will always get file/folders starting with a before it shows any cmdlets and commands in PATH-locations.
If you only want files and folders, type .\<tab>