Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to access the %temp% directory using PowerShell

Reply
 
Old 01-24-2008   #1 (permalink)
Flea#


 
 

How to access the %temp% directory using PowerShell

I need to be able to access some files in the %temp% directory on the
computer and I am unable to open that directory in PowerShell. If I open a
cmd.exe window, I can simple type cd %temp% and it opens just fine. Is there
any reason why PowerShell would have issues with this?

Thanks,
-Flea#

--
http://fleasharp.blogspot.com/

My System SpecsSystem Spec
Old 01-24-2008   #2 (permalink)
Shay Levi


 
 

Re: How to access the %temp% directory using PowerShell


PowerShell keeps environemnt variables in a special PSDrive called: env

To get all environment variables, type:

dir env:

To get a specific variable, type:

$env:<variableName>, as in:

get-childitem $env:temp



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I need to be able to access some files in the %temp% directory on the
> computer and I am unable to open that directory in PowerShell. If I
> open a cmd.exe window, I can simple type cd %temp% and it opens just
> fine. Is there any reason why PowerShell would have issues with this?
>
> Thanks,
> -Flea#

My System SpecsSystem Spec
Old 01-24-2008   #3 (permalink)
Kiron


 
 

Re: How to access the %temp% directory using PowerShell

$env:temp

--
Kiron
My System SpecsSystem Spec
Old 01-24-2008   #4 (permalink)
Brandon Shell [MVP]


 
 

Re: How to access the %temp% directory using PowerShell

$env:Temp

More Info: Get-help about_Environment_Variable

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

F> I need to be able to access some files in the %temp% directory on the
F> computer and I am unable to open that directory in PowerShell. If I
F> open a cmd.exe window, I can simple type cd %temp% and it opens just
F> fine. Is there any reason why PowerShell would have issues with
F> this?
F>
F> Thanks,
F> -Flea#


My System SpecsSystem Spec
Old 01-24-2008   #5 (permalink)
Marco Shaw [MVP]


 
 

Re: How to access the %temp% directory using PowerShell

Flea# wrote:
Quote:

> I need to be able to access some files in the %temp% directory on the
> computer and I am unable to open that directory in PowerShell. If I open a
> cmd.exe window, I can simple type cd %temp% and it opens just fine. Is there
> any reason why PowerShell would have issues with this?
>
> Thanks,
> -Flea#
>
This work for you?

PSH>$env:temp
C:\DOCUME~1\foo\LOCALS~1\Temp

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 01-24-2008   #6 (permalink)
Brandon Shell [MVP]


 
 

Re: How to access the %temp% directory using PowerShell

And the Winner is ...

three answers in seconds.... love it!

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

M> Flea# wrote:
M>
Quote:
Quote:

>> I need to be able to access some files in the %temp% directory on the
>> computer and I am unable to open that directory in PowerShell. If I
>> open a cmd.exe window, I can simple type cd %temp% and it opens just
>> fine. Is there any reason why PowerShell would have issues with
>> this?
>>
>> Thanks,
>> -Flea#
M> This work for you?
M>
PSH>> $env:temp
PSH>>
M> C:\DOCUME~1\foo\LOCALS~1\Temp
M>
M> Marco
M>
M> PowerGadgets MVP
M> http://www.powergadgets.com/mvp
M> Blog:
M> http://marcoshaw.blogspot.com


My System SpecsSystem Spec
Old 01-24-2008   #7 (permalink)
Marco Shaw [MVP]


 
 

Re: How to access the %temp% directory using PowerShell

Quote:

> three answers in seconds.... love it!
There's always room for improvements. ;-)
My System SpecsSystem Spec
Old 01-24-2008   #8 (permalink)
Flea#


 
 

Re: How to access the %temp% directory using PowerShell

Kiron, Brandon, Marco, Shay,

Thanks for all your fast replies! I am new to powershell so your expertise
is invaluable to me.

Your examples worked perfect for me and now I know about the env variables.
I do have two questions for you all though.

1. I am going to be needing to do a lot of work with PowerShell on remote
machines. PowerShell seems great when running stuff locally but I am finding
trouble trying to take what is simple locally and then applying it to remote
machines. Is there some way to create an object of a remote machine so that
whatever I execute can be ran against the remote machine?

2. For this example of the env variables, is it possible to access the env
variable of a remote machine? Basically there are files that I need to copy
from the %temp% directory of a given server and while the command $env:temp
is great for my machine, I don't know how to apply it to a remote machine.

Thanks to all for your advice and assistance!

-Flea#
--
http://fleasharp.blogspot.com/


"Shay Levi" wrote:
Quote:

>
> PowerShell keeps environemnt variables in a special PSDrive called: env
>
> To get all environment variables, type:
>
> dir env:
>
> To get a specific variable, type:
>
> $env:<variableName>, as in:
>
> get-childitem $env:temp
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > I need to be able to access some files in the %temp% directory on the
> > computer and I am unable to open that directory in PowerShell. If I
> > open a cmd.exe window, I can simple type cd %temp% and it opens just
> > fine. Is there any reason why PowerShell would have issues with this?
> >
> > Thanks,
> > -Flea#
>
>
>
My System SpecsSystem Spec
Old 01-24-2008   #9 (permalink)
Brandon Shell [MVP]


 
 

Re: How to access the %temp% directory using PowerShell

1) not until v2 (which is a long way off.) You can do alot with WMI and .NET
though. Just need an idea of what your trying to do.
2) You can find this info in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment which you can access via a .NET object.

Here is an example
$srv = "Computer"
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
$Srv)
$key = $regKey.OpenSubkey("SYSTEM\CurrentControlSet\Control\Session Manager\Environment",$true)
$key.GetValueNames() | Select-Object @{n="ValueName";e={$_}},@{n="Value";e={$key.GetValue($_)}}

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

F> Kiron, Brandon, Marco, Shay,
F>
F> Thanks for all your fast replies! I am new to powershell so your
F> expertise is invaluable to me.
F>
F> Your examples worked perfect for me and now I know about the env
F> variables. I do have two questions for you all though.
F>
F> 1. I am going to be needing to do a lot of work with PowerShell on
F> remote machines. PowerShell seems great when running stuff locally
F> but I am finding trouble trying to take what is simple locally and
F> then applying it to remote machines. Is there some way to create an
F> object of a remote machine so that whatever I execute can be ran
F> against the remote machine?
F>
F> 2. For this example of the env variables, is it possible to access
F> the env variable of a remote machine? Basically there are files that
F> I need to copy from the %temp% directory of a given server and while
F> the command $env:temp is great for my machine, I don't know how to
F> apply it to a remote machine.
F>
F> Thanks to all for your advice and assistance!
F>
F> -Flea#
F>
F> "Shay Levi" wrote:
F>
Quote:
Quote:

>> PowerShell keeps environemnt variables in a special PSDrive called:
>> env
>>
>> To get all environment variables, type:
>>
>> dir env:
>>
>> To get a specific variable, type:
>>
>> $env:<variableName>, as in:
>>
>> get-childitem $env:temp
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I need to be able to access some files in the %temp% directory on
>>> the computer and I am unable to open that directory in PowerShell.
>>> If I open a cmd.exe window, I can simple type cd %temp% and it opens
>>> just fine. Is there any reason why PowerShell would have issues
>>> with this?
>>>
>>> Thanks,
>>> -Flea#

My System SpecsSystem Spec
Old 01-24-2008   #10 (permalink)
Shay Levi


 
 

Re: How to access the %temp% directory using PowerShell


Keep in mind that (locally) $env:temp (%temp%) is the path to a USER temp
directory, not the server's.
If you want to get the system's temp path:

PS > [environment]::GetEnvironmentVariable("temp","machine")
C:\WINDOWS\TEMP


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Kiron, Brandon, Marco, Shay,
>
> Thanks for all your fast replies! I am new to powershell so your
> expertise is invaluable to me.
>
> Your examples worked perfect for me and now I know about the env
> variables. I do have two questions for you all though.
>
> 1. I am going to be needing to do a lot of work with PowerShell on
> remote machines. PowerShell seems great when running stuff locally but
> I am finding trouble trying to take what is simple locally and then
> applying it to remote machines. Is there some way to create an object
> of a remote machine so that whatever I execute can be ran against the
> remote machine?
>
> 2. For this example of the env variables, is it possible to access
> the env variable of a remote machine? Basically there are files that
> I need to copy from the %temp% directory of a given server and while
> the command $env:temp is great for my machine, I don't know how to
> apply it to a remote machine.
>
> Thanks to all for your advice and assistance!
>
> -Flea#
>
> "Shay Levi" wrote:
>
Quote:

>> PowerShell keeps environemnt variables in a special PSDrive called:
>> env
>>
>> To get all environment variables, type:
>>
>> dir env:
>>
>> To get a specific variable, type:
>>
>> $env:<variableName>, as in:
>>
>> get-childitem $env:temp
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I need to be able to access some files in the %temp% directory on
>>> the computer and I am unable to open that directory in PowerShell.
>>> If I open a cmd.exe window, I can simple type cd %temp% and it opens
>>> just fine. Is there any reason why PowerShell would have issues
>>> with this?
>>>
>>> Thanks,
>>> -Flea#

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Access Active directory with sql server in powershell PowerShell
Clean Temp Directory? .NET General
Windowc temp directory Vista file management
LPKSetup Log Files in TEMP directory Vista performance & maintenance
Temp Directory acts like media directory Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46