![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Variable as hash table issue I've got the "space invaders" PS script on the net as an example, and I saw we can declare variable as has table to group similar variable. Beside, I write my PS script with PowerShell Analyzer (http://www.powershellanalyzer.com/). In a script, I created a variable like : $path = @{ 'root' = "z:/projects" 'output' = $path.root + "/output" 'binaries' = $path.output + "/binaries" } This works well in PS Analyzer (all the "path" sub variables are resolved, but when I try to run the script in the PS command prompt, I get error because the variables 'output' and 'binaries' are not resolved. Any idea how to fix this? Thanks for your help. |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Variable as hash table issue This works. There may be a more elegant way. PS> $path = @{'root' = "c:\scripts\monad"} PS> $path +=@{'output' = $path.root + "\utils"; 'binaries' = $path.root + "\test"} PS> $path Name Value ---- ----- output c:\scripts\monad\utils binaries c:\scripts\monad\test root c:\scripts\monad PS> $path.root c:\scripts\monad PS> $path.output c:\scripts\monad\utils PS> $path.binaries c:\scripts\monad\test PS> -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty "Romu" wrote: > I've got the "space invaders" PS script on the net as an example, and I saw > we can declare variable as has table to group similar variable. > > Beside, I write my PS script with PowerShell Analyzer > (http://www.powershellanalyzer.com/). > > In a script, I created a variable like : > > $path = @{ > 'root' = "z:/projects" > 'output' = $path.root + "/output" > 'binaries' = $path.output + "/binaries" > } > > This works well in PS Analyzer (all the "path" sub variables are resolved, > but when I try to run the script in the PS command prompt, I get error > because the variables 'output' and 'binaries' are not resolved. > > Any idea how to fix this? > > Thanks for your help. |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Variable as hash table issue Thanks Richard, it works. "RichS" wrote: > This works. There may be a more elegant way. > > PS> $path = @{'root' = "c:\scripts\monad"} > PS> $path +=@{'output' = $path.root + "\utils"; 'binaries' = $path.root + > "\test"} > PS> $path > > Name Value > ---- ----- > output c:\scripts\monad\utils > binaries c:\scripts\monad\test > root c:\scripts\monad > > > PS> $path.root > c:\scripts\monad > PS> $path.output > c:\scripts\monad\utils > PS> $path.binaries > c:\scripts\monad\test > PS> > -- > Richard Siddaway > > Please note that all scripts are supplied "as is" and with no warranty > > > "Romu" wrote: > > > I've got the "space invaders" PS script on the net as an example, and I saw > > we can declare variable as has table to group similar variable. > > > > Beside, I write my PS script with PowerShell Analyzer > > (http://www.powershellanalyzer.com/). > > > > In a script, I created a variable like : > > > > $path = @{ > > 'root' = "z:/projects" > > 'output' = $path.root + "/output" > > 'binaries' = $path.output + "/binaries" > > } > > > > This works well in PS Analyzer (all the "path" sub variables are resolved, > > but when I try to run the script in the PS command prompt, I get error > > because the variables 'output' and 'binaries' are not resolved. > > > > Any idea how to fix this? > > > > Thanks for your help. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Sorting a Hash Table before outputting it to html | PowerShell | |||
| How to create a hash table from an array | PowerShell | |||
| Adding data to a hash table | PowerShell | |||
| Passing hash table by reference | PowerShell | |||
| How do I read a XML file into a hash table? | PowerShell | |||