PS1Exec

Easily execute a PowerShell script
Download

PS1Exec Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Freeware
  • Publisher Name:
  • Bill Stewart
  • Operating Systems:
  • Windows All
  • File Size:
  • 47 KB

PS1Exec Tags


PS1Exec Description

The PS1Exec application was designed to be a small tool that lets you easily execute a PowerShell script without having to worry about getting the quoting correct on the powershell.exe command line. Windows PowerShell's installation philosophy is "secure by default." One of the implications of this philosophy is that after you initially install PowerShell, you can only use it as an interactive command interpreter—it won't run scripts unless you change the default execution policy. However, most of us end up changing the default execution policy so that we can run scripts—after all, scripts are one of PowerShell's most powerful features. However, even after you enable script execution, you still can't directly schedule a PowerShell script (.ps1) in the task scheduler. This is indeed more secure, but as we all know, usability is typically inversely proportional to security. Of course, it is possible to schedule a PowerShell script if you get the powershell.exe command line just right, but this can be tricky if the script's path contains spaces or if the script requires command-line arguments that contain spaces. Also, I discovered I wanted a little bit more control over the PowerShell console window. For example, I wanted to be able to specify that a script should run hidden or minimized, or with a different console window title. To solve these problems, I wrote ps1exe32 (32-bit) and ps1exe64 (64-bit). (In this documentation, I refer to both versions, ps1exe32 and ps1exe64, as ps1exec.) ps1exe32 is for 32-bit Windows, and ps1exe64 is for 64-bit Windows. ps1exec makes it possible to easily execute a PowerShell script (.ps1) file, and it also gives the administrator some control over the PowerShell console window's initial window state and title. Here are some reasons ps1exec might be a useful tool in your environment: - ps1exec finds powershell.exe by reading the registry, so you don't need to worry about the case where the PowerShell installation directory is missing from the system path. (This should be rare, but I have seen a broken path setting on more machines that I care to remember.) - ps1exec simplifies scheduling PowerShell scripts because you don't have to worry about making a quoting mistake when constructing the powershell.exe command line. - ps1exec runs a PowerShell script in a separate console window, so you can use ps1exec to start a long-running script in a separate window without stopping your work in an existing window. - ps1exec can pause a script's console window after running the script, in case you want to view the script's output. - ps1exec allows you to specify the PowerShell console window's initial state (e.g., hidden, minimized, etc.) as well as the console window's title. Usage ps1exec's command-line syntax is as follows: ps1exe32 scriptfile ] On 64-bit platforms, use ps1exe64 instead of ps1exe32. (If you run ps1exe32 on a 64-bit machine, it will execute the 32-bit version of PowerShell instead of the 64-bit version, which is probably not what you intended.) Important! All of ps1exec's command-line arguments (-p, -q, -w, -d, -s, and -t) must appear before the script file's name on the command line. ps1exec's command-line arguments are as follows: -p Causes the console window to pause for an Enter keystroke after the script finishes running. -q ps1exec runs silently. Without -q, ps1exec will display a dialog box if it encounters an error. -w Wait for powershell.exe to close. Without -w, ps1exec will start powershell.exe to run the script and then exit immediately. (I recommend -w if you use ps1exec to schedule a PowerShell script so that the task scheduler will know when the script finishes running.) -d path Specify a starting directory for powershell.exe. If the path contains spaces, enclose it in double quotes ("). You can also use single quotes around the path (') if you are running ps1exec from a PowerShell prompt. -s windowstate windowstate is a number that specifies the default initial window state for the PowerShell console window. The default window state is 1. -t title Specify a title for the PowerShell console window. If the title contains spaces, enclose it in double quotes ("). You can also use single quotes around the title (') if you are running ps1exec from a PowerShell prompt. scriptfile Specify the filename of the PowerShell script (.ps1) file you want to run. If the script's path and/or filename contains spaces, enclose the entire path and filename in double quotes ("). You can also use single quotes around the script file's name and path (') if you are running ps1exec from a PowerShell prompt. argument If the script requires one or more command-line arguments, specify them after the script file's name. If a script's argument contains spaces, enclose it in double quotes ("). It is not currently possible to embed a double quote character (") in a script argument. You can use single quotes (') instead of double quotes, but you must double embedded single quotes.


PS1Exec Related Software