What's up with PSBASE, PSEXTENDED, PSADAPTED, and PSOBJECT?

What's up with PSBASE, PSEXTENDED, PSADAPTED, and PSOBJECT?

  • Comments 10

"Brandon Shell" asked:
> I have seen adding psbase to alot of things "fixes" problems... What is this
> psbase (thingy) and why do I have to use it?
>

There are lots of different object & data technologies in the world, each with their own particulars.  Most of us never care about those particulars, we want the data and functions and that is that.  The particulars get in the way of our problem solving.  The clearest example of this is XML.  Just try to get your data out of XML - it's a nightmere.
 
With that as a backdrop, PowerShell "adapts" various object technologies to provide a standardized object view of them.  Another way to think of it is that we project an normalized Object VIEW the same way that a database projects a VIEW of various data tables (there are good reason's why those tables exist they way they exist but as a user - they are not want I want so the DBA creates a VIEW).
 
So then what happens if the particular problem you are solving actually needs the particulars of the underlying technology?  That is where PSBASE comes in, it gives you  RAW access to the object itself.
 
We actually provide a number of VIEWS of the object:

PSBASE

the raw view of the object

PSADAPTED

the fully adapted view of the object

PSEXTENDED

just the extended elements of the object

PSOBJECT

a view of the adapter itself 

 

PS> $x=[xml]"<root><a/></root>"
PS> $x.psbase


NodeType           : Document
ParentNode         :
DocumentType       :
Implementation     : System.Xml.XmlImplementation
Name               : #document
LocalName          : #document
DocumentElement    : root
OwnerDocument      :
Schemas            : System.Xml.Schema.XmlSchemaSet
XmlResolver        :
NameTable          : System.Xml.NameTable
PreserveWhitespace : False
IsReadOnly         : False
InnerXml           : <root><a /></root>
SchemaInfo         : System.Xml.Schema.XmlSchemaInfo
BaseURI            :
Value              :
ChildNodes         : {root}
PreviousSibling    :
NextSibling        :
Attributes         :
FirstChild         : root
LastChild          : root
HasChildNodes      : True
NamespaceURI       :
Prefix             :
InnerText          :
OuterXml           : <root><a /></root>



PS> $x.psadapted

root
----
root


PS> $x.psobject


Members             : {RefineType, AsTable, MSDN, Google...}
Properties          : {root}
Methods             : {RefineType, AsTable, MSDN, Google...}
ImmediateBaseObject : #document
BaseObject          : #document
TypeNames           : {System.Xml.XmlDocument, System.Xml.XmlNode, System.Object}

 

I don’t have any extensions on XML but I’ve put a number on Process objects so let’s switch objects to show that:

PS> $p = gps powershell
PS> $p.psextended |fl *


__NounName     : Process
Name           : powershell
Handles        : 861
VM             : 202080256
WS             : 42684416
PM             : 40816640
NPM            : 9764
Path           : C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
Company        : Microsoft Corporation
CPU            : 8.78125
FileVersion    : 6.0.6000.16386 (winmain(wmbla).061024-0942)
ProductVersion : 6.0.6000.16386
Description    : PowerShell.EXE
Product        : Microsoftr Windowsr Operating System

Enjoy!

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 1 and 4 and type the answer here:
  • Post
  • Thanks Jeff.

    I suspect most of us guesed the meaning of psbase but the rest was not known by me.  I did, however suspect the psextended concept.  The others are a surprise.

    This should all come in very handy at some time I bet. Not sure where yet but, in my experience, there is no such thing as too much information.

    I will also pay even more attention to what psextended does to the underlying NET object.  I suspect that you have put a considerable amount of thought into that.

  • so what is psbase.invoke for then?  what exactly am i invoking??? method , any method on the raw net object?

  • > so what is psbase.invoke for then?

    Which object did you see an invoke method on?  It is probably an invoke of that object.  e.g.

    $x.GetType()

    will show you a type which probably has an Invoke() on it.

    Jeffrey Snover [MSFT]

    Windows PowerShell/MMC Architect

    Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

    Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

  • This may be a silly question, but if I have

     $x=[xml]"<Item>Fred</Item>"

    how do I find the value of the Item node?

    Obvious methods like

     $x.selectSingleNode("/")

    or even

     $x.psBase.selectSingleNode("/")

    simply return the error message

     format-default : The member "Item" is already present.

    And yes, I was working with an XML data set which included elements called Item - I can't think of a single name for XML elements that is more common.

  • Francis;

    This is a known problem that happens when you try to display this XML.

    You can display the XML this way: $x.PsBase.InnerXml

    And if you want to access the Item text, you can still access $x.Item

    Lee

  • "192.168.1.100" , "machine2" | foreach-object {([wmiClass] "\\$_\ROOT\CIMV2:win32_process" ).Create(

  • How can I write this line-

    <?xml-stylesheet type="text/xsl" href="transform.xsl"?>

    to the top of the XML document?  

    I keep getting this error:

    Unexpected token 'text/xsl href=transform.xsl?>' in expression or statement.

  • "192.168.1.100" , "machine2" | foreach-object {([wmiClass] "\\$_\ROOT\CIMV2:win32_process" ).Create(

  • What do you mean by RAW access?  I'm still fuzzy on the definition of psbase.

  • Here is some information on PSBASE and PSOBJECT and what each does. Windows PowerShell Blog : What's

Page 1 of 1 (10 items)