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 - discovering the type of an object

Reply
 
Old 07-23-2009   #1 (permalink)
Larry__Weiss


 
 

discovering the type of an object

I have written a small function that is helping me to discover the types of
PowerShell objects.

function WhatTypeIs($obj) {
$obj.GetType() | fl UnderlyingSystemType, BaseType
}

Is there a better way to write that function?


My System SpecsSystem Spec
Old 07-23-2009   #2 (permalink)
Hans Dingemans


 
 

Re: discovering the type of an object

PS> $x = New-Object system.xml.xmldocument
PS> WhatTypeIs $x

UnderlyingSystemType : System.Xml.XmlDocument
BaseType : System.Xml.XmlNode

PS>

Depends what you wanna know of the object and the corresponding type info.
Everthing in PowerShell is an object and has a (hidden) PSObject property to
discover more interesting things.

Below I define an XML Document object and show ALL the superclasses of the
object, upto System.Object.

PS> $x = New-Object system.xml.xmldocument
PS> $x.psobject.TypeNames
System.Xml.XmlDocument
System.Xml.XmlNode
System.Object



"Larry__Weiss" <lfw@xxxxxx> wrote in message
news:%23ssNlx4CKHA.4376@xxxxxx
Quote:

>I have written a small function that is helping me to discover the types of
>PowerShell objects.
>
> function WhatTypeIs($obj) {
> $obj.GetType() | fl UnderlyingSystemType, BaseType
> }
>
> Is there a better way to write that function?
>
My System SpecsSystem Spec
Old 07-23-2009   #3 (permalink)
Hans Dingemans


 
 

Re: discovering the type of an object

I have the following function in my $profile just to see what types are at
the end of the pipe:

PS> function Get-Type {$input | %{$_.gettype()} | select name, fullname,
basetype -unique}
PS>

PS> dir | Get-Type | ft -AutoSize

Name FullName BaseType
---- -------- --------
DirectoryInfo System.IO.DirectoryInfo System.IO.FileSystemInfo
FileInfo System.IO.FileInfo System.IO.FileSystemInfo

PS>


"Larry__Weiss" <lfw@xxxxxx> wrote in message
news:%23ssNlx4CKHA.4376@xxxxxx
Quote:

>I have written a small function that is helping me to discover the types of
>PowerShell objects.
>
> function WhatTypeIs($obj) {
> $obj.GetType() | fl UnderlyingSystemType, BaseType
> }
>
> Is there a better way to write that function?
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
testing parameter for com object type PowerShell
New-Object : Cannot load COM type Excel.Application. PowerShell
Passing credential object - what's the type? PowerShell
Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]' .NET General
Parse Log files into a strongly type Object 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