PowerShell is an incredible tool; you can even extend its powers with Azure PowerShell to control Azure’s robust functionality, allowing you to use cmdlets to provision VMs, create cloud services, and carry out a number of other complex processes.
At Stackify, we’re big fans of Azure, but that’s not to say it’s the best choice for everyone (check out our Azure vs. AWS comparison here if you’re on the fence). Regardless of whether you intend to extend to Azure or just want to use the plain-old Windows variety, you’ll need to understand the basics, and that’s why we wrote this post. Read on for more.
The PowerShell Start-Process cmdlet opens an executable file — such as a script file. If it’s not an executable file; it starts the program associated with the file.
PowerShell is a scripting language that allows users to automate and manage Windows and Windows Server systems. It can be executed in text-based shell or saved scripts. Start-Process is a cmdlet — a.k.a. command.
If you think of PowerShell as a car, then the Start-Process would be the ignition key that starts the car. The task or tasks specified in a line would be like taking a ride in your vehicle.
The Start-Process executes the specified file or files on the local computer (which is a feature that helps protect against remote hacks). The cmdlet allows users to specify parameters that trigger options.
Here’s how to access the CLI:
When using the PowerShell CLI, the basic syntax of a Power-Start cmdlet is:
PS C:\> Start-Process <String>
To start a program called notepad on the C drive, use:
PS C:\> Start-Process notepad.exe
Parameters add more power to the cmdlet. For example, this will start Notepad, maximize the window, and keep it until the user is done with Notepad:
PS C:\> Start-Process -FilePath "notepad" -Wait -WindowStyle Maximized
The parameters that can be used include:
Try Stackify’s free code profiler, Prefix, to write better code on your workstation. Prefix works with .NET, Java, PHP, Node.js, Ruby, and Python.
PS C:\> $Browser = "C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE" PS C:\> Start-Process $Browser
PS C:\> $Path = "C:\Program Files\Internet Explorer" PS C:\> Start-Process -WorkingDirectory $Path iexplore.exe -WindowStyle Maximized
PS C:\> Start-Process notepad.exe OpenThisFile.txt
PS C:\> Start-Process notepad.exe PS C:\> $NotepadProc = Get-Process -Name notepad PS C:\> $NotepadProc.WaitForExit() PS C:\> $Path = "C:\Program Files\Internet Explorer" PS C:\> Start-Process -WorkingDirectory $Path iexplore.exe
PS C:\> start-process PrintThisFile.txt -verb Print
PS C:\> Start-Process -FilePath "powershell" -Verb runAs
Stackify's APM tools are used by thousands of .NET, Java, PHP, Node.js, Python, & Ruby developers all over the world.
Explore Retrace's product features to learn more.
If you would like to be a guest contributor to the Stackify blog please reach out to [email protected]