<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title><![CDATA[[SecurityRatty] tag: env]]></title>
    <link>http://www.securityratty.com/tag/env</link>
    <description></description>
    <pubDate>Sun, 02 Dec 2007 08:27:00 +0000</pubDate>
    <generator>iRatty Engine</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <item>
      <title><![CDATA[Execute in PowerShell]]></title>
      <link>http://www.securityratty.com/article/614775a6ac80776e11892eefa05298c1</link>
      <guid>http://www.securityratty.com/article/614775a6ac80776e11892eefa05298c1</guid>
      <description><![CDATA[As part of a disaster recovery script, early on I wanted to ensure that all of the vdirs on a server were using ASP.NET 2.0. That meant that I wanted to run
aspnet regiis.exe -r
but I didn't want to...]]></description>
      <content:encoded><![CDATA[<p>As part of a disaster recovery script, early on I wanted to ensure that all of the vdirs on a server were using ASP.NET 2.0. That meant that I wanted to run</p> <blockquote> <p><tt>aspnet_regiis.exe -r</tt></p></blockquote> <p>but I didn't want to make any assumptions about what drive or directory Windows was installed in. What I wanted was something like this:</p> <blockquote> <p><tt>%WINDIR%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -r</tt></p></blockquote> <p>In PowerShell, an easy way to get the value of an environment variable is to use the $env namespace like so:</p> <blockquote> <p><tt>$env:windir</tt></p></blockquote> <p>but when I put this all together and tried to run it, PowerShell didn't parse it the way I expected:</p> <blockquote><tt>$env:windir\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -r<br>Unexpected token '\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe' in expression or statement.</tt> </blockquote> <p>Putting quotes around it doesn't help. Now PowerShell assumes you want a string.</p> <blockquote><tt>"$env:windir\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe" -r<br>You must provide a value expression on the right-hand side of the '-' operator.</tt> </blockquote> <p>What you need to do is make it clear to PowerShell that you want to execute the next string as a command. The way to do this is to use the call operator &amp; (ampersand). Here's what I ended up with:</p> <blockquote><tt>&amp; $env:windir\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -r</tt></blockquote> <p>That's more like it. This is the sort of little roadblock that tends to frustrate people trying to use PowerShell for the first time. I hope this helps!</p><img src ="http://pluralsight.com/blogs/keith/aggbug/49336.aspx" width = "1" height = "1" />]]></content:encoded>
      <pubDate>Sun, 02 Dec 2007 08:27:00 +0000</pubDate>
      <category domain="http://www.securityratty.com/tag/powershell">powershell</category>
      <category domain="http://www.securityratty.com/tag/50727aspnet regiis">50727aspnet regiis</category>
      <category domain="http://www.securityratty.com/tag/env">env</category>
      <category domain="http://www.securityratty.com/tag/powershell assumes">powershell assumes</category>
      <category domain="http://www.securityratty.com/tag/env namespace">env namespace</category>
      <category domain="http://www.securityratty.com/tag/exe">exe</category>
      <category domain="http://www.securityratty.com/tag/netframeworkv2">netframeworkv2</category>
      <category domain="http://www.securityratty.com/tag/windirmicrosoft">windirmicrosoft</category>
      <category domain="http://www.securityratty.com/tag/call operator">call operator</category>
      <source url="http://pluralsight.com/blogs/keith/archive/2007/12/02/49336.aspx">Execute in PowerShell</source>
    </item>
  </channel>
</rss>
