Welcome to MSDN Blogs Sign in | Join | Help

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

Published Friday, November 24, 2006 6:27 PM by PowerShellTeam
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

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

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.

Saturday, November 25, 2006 12:59 PM by Jim V

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

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

Wednesday, November 29, 2006 3:04 PM by chris

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

> 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

Thursday, November 30, 2006 9:25 AM by PowerShellTeam

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

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.

Thursday, February 15, 2007 8:54 AM by Francis

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

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

Thursday, February 15, 2007 11:31 AM by PowerShellTeam

# Starting processes on remote machines

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

Thursday, March 29, 2007 3:41 AM by one-liners

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

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.

Thursday, April 26, 2007 5:47 PM by colinn

# Starting processes on remote machines

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

Sunday, October 28, 2007 2:51 AM by Karl Prosser (MVP) on Powershell

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

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

Friday, December 21, 2007 12:42 PM by Like_Wise

# Windows PowerShell Blog : What's up with PSBASE, PSEXTENDED, PSADAPTED, and PSOBJECT?

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

Thursday, February 05, 2009 7:35 PM by It's my life... And I live it...

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker