Run a script in textfile from powershell

Posted on 2011-05-12
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

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    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…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now