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





“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