When people ask me what I do in my free time, this is the short answer. It’s a never ending story.

How to execute PowerShell scrips

For all upcoming projects you have to be aware how to run them. I assume that you are familiar with execution policy and file blocking. All comments like “how to run…” will be deleted.

Most simple method to run anything with no prompts is to unblock data stream for particular file.

  • Unblock-File – Cmdlet available since PowerShell version 3.0.
  • Modify Data Stream – works for everything and everywhere. Examples:
    cmd /c echo.>myFile.ps1:Zone.Identifier – clears stream preferences
    notepad C:\myFolder\myFile.exe:Zone.Identifier – edit stream preferences in notepad

Microsoft articles about execution policy:

If PowerShell script execution is disabled on the system and you are not allowed to modify the policy, read the file as a single line string, convert the content to script block and execute it with call operator ‘&’. Example:

& ([ScriptBlock]::Create((Get-Content .\MyScript.ps1 | Out-String)))

Notify of
Inline Feedbacks
View all comments