Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Variable as hash table issue

Reply
 
Old 01-19-2007   #1 (permalink)
Romu


 
 

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 SpecsSystem Spec
Old 01-20-2007   #2 (permalink)
RichS


 
 

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 SpecsSystem Spec
Old 01-22-2007   #3 (permalink)
Romu


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46