Share via

PSHost.PrivateData Property


Used to allow the host to pass private data through a Runspace to cmdlets running inside that Runspace's runspace. The type and nature of that data is entirely defined by the host, but there are some caveats:

 virtual property System::Management::Automation::PSObject ^ PrivateData { System::Management::Automation::PSObject ^ get(); };
public virtual System.Management.Automation.PSObject PrivateData { get; }
member this.PrivateData : System.Management.Automation.PSObject
Public Overridable ReadOnly Property PrivateData As PSObject

Property Value

The default implementation returns null.


If the host is using an out-of-process Runspace, then the value of this property is serialized when crossing that process boundary in the same fashion as any object in a pipeline is serialized when crossing process boundaries. In this case, the BaseObject property of the value will be null.

If the host is using an in-process Runspace, then the BaseObject property can be a non-null value a live object. No guarantees are made as to the app domain or thread that the BaseObject is accessed if it is accessed in the runspace. No guarantees of threadsafety or reentrancy are made. The object set in the BaseObject property of the value returned by this method is responsible for ensuring its own threadsafety and re-entrance safety. Note that thread(s) accessing that object may not necessarily be the same from one access to the next.

The return value should have value-semantics: that is, changes to the state of the instance returned are not reflected across processes. Ex: if a cmdlet reads this property, then changes the state of the result, that change will not be visible to the host if the host is in another process. Therefore, the implementation of get for this property should always return a unique instance.

Applies to