Windows Vista Forums

How to access the %temp% directory using PowerShell

  1. #1


    Flea# Guest

    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

  2. #2


    Shay Levi Guest

    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

    > 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

  3. #3


    Kiron Guest

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

    $env:temp

    --
    Kiron

      My System SpecsSystem Spec

  4. #4


    Brandon Shell [MVP] Guest

    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

  5. #5


    Marco Shaw [MVP] Guest

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

    Flea# wrote:

    > 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

  6. #6


    Brandon Shell [MVP] Guest

    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>

    >> 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

  7. #7


    Marco Shaw [MVP] Guest

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


    > three answers in seconds.... love it!
    There's always room for improvements. ;-)

      My System SpecsSystem Spec

  8. #8


    Flea# Guest

    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:

    >
    > 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
    >

    > > 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

  9. #9


    Brandon Shell [MVP] Guest

    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>

    >> 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

    >>> 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

  10. #10


    Shay Levi Guest

    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

    > 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:
    >

    >> 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

    >>> 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

Page 1 of 2 12 LastLast
How to access the %temp% directory using PowerShell

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Active directory with sql server in powershell Martin PowerShell 3 03 May 2009
Clean Temp Directory? fabrizio.db .NET General 2 28 Jan 2009
Windowc temp directory André Landreau Vista file management 8 17 Dec 2007
LPKSetup Log Files in TEMP directory David A. Lessnau Vista performance & maintenance 0 10 Apr 2007
Temp Directory acts like media directory Henry Jones Vista General 2 20 Jan 2007