Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: How to run PowerShell scripts easily from start menu

18 Mar 2015   #1
Surfin

Windows 7 Pro x64
 
 
How to run PowerShell scripts easily from start menu

Hi, I have a very big problem

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 )
  • 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 )

Can anybody help me to be faster ?! Please


My System SpecsSystem Spec
.
18 Mar 2015   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 System SpecsSystem Spec
18 Mar 2015   #3
Surfin

Windows 7 Pro x64
 
 

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 System SpecsSystem Spec
.

19 Mar 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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


Attached Files
File Type: ps1 th-364505.ps1 (1.0 KB, 1 views)
My System SpecsSystem Spec
19 Mar 2015   #5
Surfin

Windows 7 Pro x64
 
 

Wow ! Nice workaround ! 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)

If ever someone find another workaround, I would be VERY happy
My System SpecsSystem Spec
19 Mar 2015   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 System SpecsSystem Spec
Reply

 How to run PowerShell scripts easily from start menu




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
How do I pin a folder to Start Menu and have it show Task side menu?
I guess this is best explained with images, so here's what I want. (If possible of course). https://scontent-b-mia.xx.fbcdn.net/hphotos-xap1/t31.0-8/10958975_1431057283852542_3719755294889004032_o.jpg So in this screenshot you can see my Start Menu, notice that some of this icons (Steam,...
Customization
Web Cam Unable To Start Easily (DELL INSPIRON 1564 WINDOWS 7)
Hi, Eveyone as the title says. Why does it takes too long to start web cam from web cam central,i have to adjust the screen lid multiple times,and always need to press web cam portion. I had removed the lid frame,to check the web cam,for looseness,but everything looks normal. I don't...
Hardware & Devices
Start Menu - Add Libraries to Search in Start Menu
How to Pin Libraries to Search and See More Results in Start Menu This tutorial will show you how to add links for the Libraries in the Start Menu, to be able to search from the Start Menu Search Bar and See More Results directly within the Libraries. You will only be able to add a total of...
Tutorials
Two Scripts: START then END Application
I'm running low on resources and am not wanting to upgrade, so it looks like a script to the rescue! Basically I work with Oracle 11g on my computer. Here are the 2 scripts that I'm looking to do. Please help. Thanks. Script 1: Start Oracle 11g START Service A START Service B START...
General Discussion
menu view of personal folders pinned to start menu
Hi, I have created and pinned some personal folders to the start menu. They now appear on the left hand side of the start menu, along with the other applications. Here are my questions: 1) How can I set up those folders so that they would appear with the little arrow on the right that will...
Customization
Menu sound effects not working for Windows 7 start menu
I upgraded from Windows XP to 7. I have "menu command" and "menu pop-up" sound effects set but they are not working for the Windows 7 start menu. They used to work for XP. It was helpful to hear a sound effect whenever a menu expanded or item was pressed in the start menu. I know this may be a...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 13:48.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App