[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Run a script in textfile from powershell

Posted on 2011-05-12
Medium Priority
Last Modified: 2012-05-11
If I have the script,
move "C:\textfile1.txt" "C:\NewFolder"

Open in new window

in a textfile called "C:/ScriptToExecute.txt", how do I execute the script by reading the script via powershell?

Please excuse my newbieness
Question by:jdn717
1 Comment
LVL 13

Accepted Solution

soostibi earned 1996 total points
ID: 35749695
The easiest way is to rename your file to c:\ScriptToExecute.PS1, then run it by:


Open in new window

If it is not possible to rename it:
&([scriptblock]::Create((Get-Content c:\ScriptToExecute.txt)))

Open in new window


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Loops Section Overview

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question