PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

image rotation

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Scripts

10-24-2014 - $HostState
10-23-2014 - Get-BinaryType
10-23-2014 - Read-ImageExportDirectory

Latest Announcements/Events

10-21-2014 - Get High Quality Real And fake Passports,Driver’s...
10-15-2014 - Class Dismissed
10-12-2014 - The Case for PowerShell

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Controlling Execution of Executables

All PowerShell versions

PowerShell treats executables (files with extension EXE) like any other command. You can, however, make sure that PowerShell will not execute any or execute only a list of approved applications.

The default setting allows any EXE to be executed:

PS> $ExecutionContext.SessionState.Applications

This setting would make sure only ping.exe and regedit.exe can run:


And this is the result:

PS> $ExecutionContext.SessionState.Applications

Obviously, you can simply revert this setting to get back the default behavior:

PS> $ExecutionContext.SessionState.Applications.Add('*')

PS> explorer


So as-is, this setting will just make it harder to execute EXEs (or prevent accidental execution of unwanted EXEs). To use it as a security measure, you would also need to turn off the so-called “Language Mode”.

When turned off, you no longer can access .NET objects directly, thus you would not be able to revert the change anymore in the current PowerShell session. We’ll cover the full language mode setting tomorrow.

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.