• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Execute scripts in current scope?

J

JeremyG

#1
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 Computer

B

Brandon Shell

#2
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 Computer

D

David

#3
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 Computer

J

JeremyG

#4
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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)