Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

4,253 views
Skip to first unread message

ssg31415926

unread,
Sep 3, 2008, 5:44:58 AM9/3/08
to
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?

ssg31415926

unread,
Sep 3, 2008, 5:59:42 AM9/3/08
to

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

Oisin (x0n) Grehan [MVP]

unread,
Sep 3, 2008, 10:33:03 AM9/3/08
to
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

unread,
Sep 4, 2008, 5:00:31 AM9/4/08
to
On Sep 3, 3:33 pm, "Oisin (x0n) Grehan [MVP]" <ois...@gmail.com>
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...@gmail.com> 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.

0 new messages