How can I resolve %WINDIR% inside a PowerShell script?


  1.    03 Sep 2008 #1
    ssg31415926 Guest

    How can I resolve %WINDIR% inside a PowerShell script?


    I want to run this command from within a PowerShell script:

    fsutil hardlink create %WINDIR%\system32\windowspowershell
    \v1.0\psh.exe %WINDIR%\system32\windowspowershell\v1.0\powershell.exe

    It works from with cmd.exe, as you'd expect, but not from within
    powershell.exe. (I didn't really expect it to, though.)

    It there a way to get powershell to resolve system environment
    variables or do I need to retrieve them using PowerShell and build a
    command line?
      My System SpecsSystem Spec

  2.    03 Sep 2008 #2
    ssg31415926 Guest

    Re: How can I resolve %WINDIR% inside a PowerShell script?


    On Sep 3, 10:44 am, ssg31415926 <newsjunkm...@xxxxxx> wrote:

    > I want to run this command from within a PowerShell script:
    >
    > fsutil hardlink create %WINDIR%\system32\windowspowershell
    > \v1.0\psh.exe %WINDIR%\system32\windowspowershell\v1.0\powershell.exe
    >
    > It works from with cmd.exe, as you'd expect, but not from within
    > powershell.exe. (I didn't really expect it to, though.)
    >
    > It there a way to get powershell to resolve system environment
    > variables or do I need to retrieve them using PowerShell and build a
    > command line?
    Never mind. Found it: $env:windir, hence:

    fsutil hardlink create $env:WINDIR\system32\windowspowershell
    \v1.0\psh.exe $env:WINDIR\system32\windowspowershell
    \v1.0\powershell.exe
      My System SpecsSystem Spec

  3.    03 Sep 2008 #3
    Oisin (x0n) Grehan [MVP] Guest

    Re: How can I resolve %WINDIR% inside a PowerShell script?


    But if you ever did need to resolve one of those kind of environment
    variables, you could do it like this:

    PS> [System.Environment]::ExpandEnvironmentVariables("%WINDIR%")
    C:\Windows

    - Oisin


    ssg31415926 wrote:

    > On Sep 3, 10:44�am, ssg31415926 <newsjunkm...@xxxxxx> wrote:

    > > I want to run this command from within a PowerShell script:
    > >
    > > fsutil hardlink create %WINDIR%\system32\windowspowershell
    > > \v1.0\psh.exe %WINDIR%\system32\windowspowershell\v1.0\powershell.exe
    > >
    > > It works from with cmd.exe, as you'd expect, but not from within
    > > powershell.exe. �(I didn't really expect it to, though.)
    > >
    > > It there a way to get powershell to resolve system environment
    > > variables or do I need to retrieve them using PowerShell and build a
    > > command line?
    >
    > Never mind. Found it: $env:windir, hence:
    >
    > fsutil hardlink create $env:WINDIR\system32\windowspowershell
    > \v1.0\psh.exe $env:WINDIR\system32\windowspowershell
    > \v1.0\powershell.exe
      My System SpecsSystem Spec

  4.    04 Sep 2008 #4
    ssg31415926 Guest

    Re: How can I resolve %WINDIR% inside a PowerShell script?


    On Sep 3, 3:33 pm, "Oisin (x0n) Grehan [MVP]" <ois...@xxxxxx>
    wrote:

    > But if you ever did need to resolve one of those kind of environment
    > variables, you could do it like this:
    >
    > PS> [System.Environment]::ExpandEnvironmentVariables("%WINDIR%")
    > C:\Windows
    >
    > - Oisin
    >
    > ssg31415926wrote:

    > > On Sep 3, 10:44 am,ssg31415926<newsjunkm...@xxxxxx> wrote:

    > > > I want to run this command from within a PowerShell script:
    >

    > > > fsutil hardlink create %WINDIR%\system32\windowspowershell
    > > > \v1.0\psh.exe %WINDIR%\system32\windowspowershell\v1.0\powershell.exe
    >

    > > > It works from with cmd.exe, as you'd expect, but not from within
    > > > powershell.exe. (I didn't really expect it to, though.)
    >

    > > > It there a way to get powershell to resolve system environment
    > > > variables or do I need to retrieve them using PowerShell and build a
    > > > command line?
    >

    > > Never mind. Found it: $env:windir, hence:
    >

    > > fsutil hardlink create $env:WINDIR\system32\windowspowershell
    > > \v1.0\psh.exe $env:WINDIR\system32\windowspowershell
    > > \v1.0\powershell.exe
    That could be handy. Thanks.
      My System SpecsSystem Spec

How can I resolve %WINDIR% inside a PowerShell script?

Similar Threads
Thread Forum
How to retrieve the script name inside Powershell?
$args contains the passing arguements, but no script name. How to get the script name inside itself in Powershell? Thanks!
PowerShell
Script to read information inside a pdf file
Hi ! I use the following VBA programmation to complete a pdf form (using SendKeys). Once the form is completed, the users can make modifications....
VB Script
Converting a BAT script into a PowerShell Script
Hi all, I am in the process of trying to convert a couple of our .BAT scripts into powershell scripts, however, I'm running into a couple of pesky...
PowerShell
Running a command from inside a script, command line is corrupted
Hello, I am trying to give Powershell a chance, since it seems like it may have some promise. I have this powershell script that needs to run...
PowerShell
Powershell script help
I'm new to this and have pieced together a script, but it is not working. Can you help me figure out why I can't get this to email to me? I can get...
PowerShell
a powershell window inside visual studio?
hi, seems to me it would be *very* convenient to be able to open up a powershell session inside visual studio. i've searched a bit but haven't...
PowerShell
when run powershell script as windows service ,powershell fail
On windows 2008 ,run powershell script by windows serivice application ,but this script always failed due to the following .Net runtime error ...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 22:20.
    .