<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use PowerShell Environmental Variables to Store Temporary Information</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/22/use-powershell-environmental-variables-to-store-temporary-information.aspx</link><description>Use the Windows PowerShell environmental drive to store temporary information, and still use the Set-StrictMode cmdlet.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use PowerShell Environmental Variables to Store Temporary Information</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/22/use-powershell-environmental-variables-to-store-temporary-information.aspx#3488123</link><pubDate>Thu, 22 Mar 2012 15:22:16 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3488123</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@K_Schulte You are right, I could eliminate the Else clause in the script. You are also right that this is a simple solution to the problem of storing simple data. It should be a good tool to use for that. For more complex data, I certainly agree with you about exporting the XML.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3488123" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell Environmental Variables to Store Temporary Information</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/22/use-powershell-environmental-variables-to-store-temporary-information.aspx#3488051</link><pubDate>Thu, 22 Mar 2012 08:15:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3488051</guid><dc:creator>K_Schulte</dc:creator><description>&lt;p&gt;Hi Ed,&lt;/p&gt;
&lt;p&gt;a good idea! Just save the value of my persistent vars to the registry!&lt;/p&gt;
&lt;p&gt;btw: There&amp;#39;s one thing, I would change in the InitializeVariableFromEnv.ps1 script.&lt;/p&gt;
&lt;p&gt;I would eliminate the else part of the condition and just write:&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;if(-not (test-path -path env:\a))&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{ New-Item -Name a -Path env: -Value 0 | out-null }&lt;/p&gt;
&lt;p&gt;[int]$a = $env:a&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;It&amp;#39;s good to remember that the environment variables are strings and need to be casted to the appropriate types! But we have to be aware of the fact, that this solution is not generally applicable because we stick to storing integers here. Simple types can quite easily be stored in environment strings like that.&lt;/p&gt;
&lt;p&gt;If you try to store an array like &amp;quot;$env:a=1,2,3,4,5&amp;quot; you&amp;#39;ll get &amp;quot;1 2 3 4 5&amp;quot; back, which can be restored to an array by [int[]]$a=$env:a -split &amp;quot; &amp;quot; e.g.&lt;/p&gt;
&lt;p&gt;Things will quickly become complicated if you have to store anything else than simple types in environment variables and we are better off using the Export-CliXml (and Import-CliXml) Cmdlet to persist our information in files.&lt;/p&gt;
&lt;p&gt;Klaus&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3488051" width="1" height="1"&gt;</description></item></channel></rss>