Windows Vista Forums

Execute scripts in current scope?

  1. #1


    JeremyG Guest

    Execute scripts in current scope?

    I think i'm missing something big. I'm hoping that the answer is simple, if
    not I'm going to be very dismayed with powershell.

    I want to run scripts that setup my current working environment with
    variables, objects and functions. This way I can start a new power-shell,
    run a script and be at a useful state immediately.

    In the most simplest form, i want to run this "goodbye.ps1" script:
    $x = "Goodbye World"

    Then at the command line, I want to have this effective outcome:

    PS> $x
    PS> ./goodbye.ps1
    PS> $x
    Goodbye World

    Obviously the ability to do this would be awesome. If this is possible I
    can write a script that would create Active Directory objects, pre-set arrays
    or XML files. Then work with them free-form depending on what i need to do.

    Help!

      My System SpecsSystem Spec

  2. #2


    Brandon Shell Guest

    Re: Execute scripts in current scope?

    It is easy
    PS> get-help about_scope -full

    "JeremyG" <JeremyG@discussions.microsoft.com> wrote in message
    news:842BF40D-B4AA-4D22-89FF-E4C77269772F@microsoft.com...
    >I think i'm missing something big. I'm hoping that the answer is simple,
    >if
    > not I'm going to be very dismayed with powershell.
    >
    > I want to run scripts that setup my current working environment with
    > variables, objects and functions. This way I can start a new
    > power-shell,
    > run a script and be at a useful state immediately.
    >
    > In the most simplest form, i want to run this "goodbye.ps1" script:
    > $x = "Goodbye World"
    >
    > Then at the command line, I want to have this effective outcome:
    >
    > PS> $x
    > PS> ./goodbye.ps1
    > PS> $x
    > Goodbye World
    >
    > Obviously the ability to do this would be awesome. If this is possible I
    > can write a script that would create Active Directory objects, pre-set
    > arrays
    > or XML files. Then work with them free-form depending on what i need to
    > do.
    >
    > Help!



      My System SpecsSystem Spec

  3. #3


    David Guest

    RE: Execute scripts in current scope?

    You just need to "dot" the script. Put a period in front of the script name
    when executing, similar to the UNIX shells. (space between the period and the
    script name).
    PS>. ./goodbye.ps1

    "JeremyG" wrote:

    > I think i'm missing something big. I'm hoping that the answer is simple, if
    > not I'm going to be very dismayed with powershell.
    >
    > I want to run scripts that setup my current working environment with
    > variables, objects and functions. This way I can start a new power-shell,
    > run a script and be at a useful state immediately.
    >
    > In the most simplest form, i want to run this "goodbye.ps1" script:
    > $x = "Goodbye World"
    >
    > Then at the command line, I want to have this effective outcome:
    >
    > PS> $x
    > PS> ./goodbye.ps1
    > PS> $x
    > Goodbye World
    >
    > Obviously the ability to do this would be awesome. If this is possible I
    > can write a script that would create Active Directory objects, pre-set arrays
    > or XML files. Then work with them free-form depending on what i need to do.
    >
    > Help!


      My System SpecsSystem Spec

  4. #4


    JeremyG Guest

    RE: Execute scripts in current scope?

    Ah ha! Thank you!

    I knew it had to be something simple....for some reason I wasn't getting
    that from any of the docs I was reading. I dont have much of a *nix
    background or I probably would have known right off.

    Now the world is my play thing!

    "David" wrote:

    > You just need to "dot" the script. Put a period in front of the script name
    > when executing, similar to the UNIX shells. (space between the period and the
    > script name).
    > PS>. ./goodbye.ps1
    >
    > "JeremyG" wrote:
    >
    > > I think i'm missing something big. I'm hoping that the answer is simple, if
    > > not I'm going to be very dismayed with powershell.
    > >
    > > I want to run scripts that setup my current working environment with
    > > variables, objects and functions. This way I can start a new power-shell,
    > > run a script and be at a useful state immediately.
    > >
    > > In the most simplest form, i want to run this "goodbye.ps1" script:
    > > $x = "Goodbye World"
    > >
    > > Then at the command line, I want to have this effective outcome:
    > >
    > > PS> $x
    > > PS> ./goodbye.ps1
    > > PS> $x
    > > Goodbye World
    > >
    > > Obviously the ability to do this would be awesome. If this is possible I
    > > can write a script that would create Active Directory objects, pre-set arrays
    > > or XML files. Then work with them free-form depending on what i need to do.
    > >
    > > Help!


      My System SpecsSystem Spec

Execute scripts in current scope?

Similar Threads
Thread Forum
Find my current drive letter and execute a program from it while i
HI! The problem is that when i change the directory to usbletter:\SYSTEM i can't find a way to execute a program from the source directory where...
VB Script
Scope of objects in scripts
I am trying to modify a script (http://www.terminal23.net/2007/04/powershell_auditing_permissions.html) to create an array of custom objects prior...
PowerShell
Execute PowerShell Scripts via http url requests
Is there a way to execute PowerShells commands/scripts via http url requests? An example would be something like:...
PowerShell
How to execute (perl) scripts in Powershell without DOS box
Hi folks, I am trying to execute a bunch of perl scripts from within a Powershell by simply writing their name (and pressing Return, of course)....
PowerShell
Executing scripts in the current directory
I guess I've casually accepted that in Monad ... then PowerShell ... that I can't execute a script by typing: ScriptName or ScriptName.ps1...
PowerShell
Right-click execute scripts ?
Hi, have installed PowerShell How can I have scripts auoexecute whith a right-click->execute action ( as can be achieved with others scripts)...
PowerShell
AD LogOn Scripts Execute permissions
Testing Environmet: Ms Virtual Server 2k5 R2 Testing Environment Host OS: Enterprise Server 2k3 x64 Edition Testing Environment Hardware: Intel...
Vista account administration