How to run PowerShell scripts easily from start menu


  1. Posts : 3
    Windows 7 Pro x64
       #1

    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 Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    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


  3. Posts : 3
    Windows 7 Pro x64
    Thread Starter
       #3

    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


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    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
    How to run PowerShell scripts easily from start menu Attached Files
      My Computer


  5. Posts : 3
    Windows 7 Pro x64
    Thread Starter
       #5

    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 Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    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


 

  Related Discussions
Our Sites
Site Links
About 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 01:14.
Find Us