How to run PowerShell scripts easily from start menu

Surfin

New member
Local time
9:28 PM
Messages
3
Hi, I have a very big problem :p

I put 2 scripts in C:\Windows (pong.ps1 and pung.bat).
And I added ".PS1" in the PathExt environment variable.

But :

  • When I clic Start button, and type pung, my batch script pung.bat appears in the Programs list and is selected so I just need to press [Enter] to run it (this is cool :cool:)

  • But when I clic Start button, and type pong, my powershell script pong.ps1 doesn't appears in the Programs list. I have to type pong.ps1 (so it's a little bit longer for me :p)

Can anybody help me to be faster ?! Please
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Pro x64
Hello Surfin, and welcome to SevenForums,

Mmm, that's a very big problem indeed. Two simple steps will help that:

1) Create a Shortcut of this pong.ps1 file. (The name of this Shortcut should match the name of the target file.)
2) Place this new Shortcut in C:\Users\%Username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs (or C:\ProgramData\Microsoft\Windows\Start Menu\Programs).


The PATHEXT environment variable only serves a purpose within the command line. It is not used anywhere else.
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Thanks for this answer ;)
But I forgot to tell that I want to copy a lot of PowerShell scripts in C:\Windows so it will be difficult to create a shortcut for every one :(
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Pro x64
No task be too difficult when the power of PowerShell is on our side.

Attached is a PowerShell script that will automate the creation of Shortcut files for you.

Simply run the PowerShell script once you have placed all desired .ps1 files in C:\Windows.


Preview:
Code:
# Make Shortcuts of select files residing in $source_location at $destination_location

#
[string] $source_location = "C:\Windows"
[array]  $file_masks = "*.ps1"
[string] $destination_location = "C:\Users\$env:USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\PowerShellProgs"
#

[array]$files = Get-ChildItem -Path ( "$source_location" + '\*' ) -Include $file_masks -ea 0
if (!$?) {'Error: ' + "$($error[0].Exception.Message)"; Start-Sleep 2; exit 1 }

if (!(Test-Path $destination_location -PathType container)) { 'The destination path ' + """$destination_location""" + ' does not exist. It will be created.' ; New-Item $destination_location -ItemType container >$null}

$shell = New-Object -ComObject 'WScript.Shell'
foreach ($file in $files) {
    $lnk = $shell.CreateShortcut( "$( Join-Path $destination_location $(Split-Path -Leaf $($file.FullName)))" + ".lnk" )
    $lnk.TargetPath = $file.FullName
    $lnk.WorkingDirectory = Split-Path -Parent $file.FullName
    $lnk.Save()
}

"`nDone."
Start-Sleep 2
exit 0
 

Attachments

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Wow ! Nice workaround :cool: ! Thank you...

I will use it, but I'm still frustrated that the PS1 files are not as easy to call as batch files with the Run dialog (Win+R) :cry:

If ever someone find another workaround, I would be VERY happy :party:
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Pro x64
Unfortunately, I don't think there is such a workaround for allowing the functionality of running a file without typing it's extension into the Run dialog.

The only file types where you are able to omit the file extension for, in the Run dialog, are strictly limited to, *.exe, *.pif, *.com, *.bat and *.cmd.
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Back
Top