Thread: Set-Variable
View Single Post
Old 10-25-2006   #3 (permalink)
Keith Hill [MVP]


 
 

Re: Set-Variable

"Fred J." <swim.instructor@gmail.com> wrote in message
news:1161749627.048671.242200@m7g2000cwm.googlegroups.com...
> Why isn't a value returned when I do this? All I get is a prompt.
> PS > $xy.description


FYI you can also access the description like this:

6# (Get-Variable xy).Description
this variable contains a color

However to answer you question as to why "$xy" didn't work as you expected,
when you access the variable directly using the syntax "$xy" you are telling
PowerShell that you just want the "value" portion of the variable. You can
confirm this by executing:

> $xy | get-member


You will see that the object emitted by $xy is just a string. If you had
executed "Set-Variable -name xy -value 3.14" then $xy would emit a double.
Now when you execute "Get-Variable xy" you will get the full PowerShell
PSVariable object with all the information about the variable: name, value,
description. For example:

13# Get-Variable xy | gm

TypeName: System.Management.Automation.PSVariable

Name MemberType Definition
---- ---------- ----------
Equals Method System.Boolean Equals(Object obj)
GetHashCode Method System.Int32 GetHashCode()
GetType Method System.Type GetType()
get_Attributes Method
System.Collections.ObjectModel.Collection`1[[Sy...
get_Description Method System.String get_Description()
get_Name Method System.String get_Name()
get_Options Method System.Management.Automation.ScopedItemOptions
....
get_Value Method System.Object get_Value()
IsValidValue Method System.Boolean IsValidValue(Object value)
set_Description Method System.Void set_Description(String value)
set_Options Method System.Void set_Options(ScopedItemOptions
value)
set_Value Method System.Void set_Value(Object value)
ToString Method System.String ToString()
Attributes Property
System.Collections.ObjectModel.Collection`1[[Sy...
Description Property System.String Description {get;set;}
Name Property System.String Name {get;}
Options Property System.Management.Automation.ScopedItemOptions
....
Value Property System.Object Value {get;set;}
OpenHelpTopic ScriptMethod System.Object OpenHelpTopic();

HTH,
Keith


My System SpecsSystem Spec