Enhancing PSVersionTable

Not too long ago I posted a PowerShell function that could provide detail abut the PowerShell engine driving your current PowerShell session. I like having a function that writes an object to the pipeline, can take parameters and offer help documentation. But there’s an alternative approach you could also take.

Most of the information is already in $PSVersiontable. So why not use that as a vehicle? This variable is a simple hashtable that is constructed every time you start a PowerShell session. This means you can add key/value pairs to it with the Add() method.

Remember that this will only change the variable for the current PowerShell session. If you wanted to always have this extended information, you would need to add these lines to your PowerShell profile script or create a simple function. If you go that route, you’ll want to include some testing and error handling because you can’t add a value that already exists. When you are done you get results like these:



$PSVersiontable is not an ordered hashtable so you can’t predict the display order, but it does offer a quick and dirty way to store additional information you might want to reference.

2 thoughts on “Enhancing PSVersionTable

  1. This was awesome but I ran into an issue when trying to remote –

    This error would occur

    WriteErrorStream : True
    Exception : System.Management.Automation.Remoting.PSRemotingDataStructureException: An error has occurred
    which Windows PowerShell cannot handle. A remote session might have ended. —>
    System.ArgumentException: The type of the value System.Management.Automation.PSLanguageMode is
    not valid. The PSPrimitiveDictionary class accepts only values of types that are fully
    serializable over Windows PowerShell remoting. See the Help topic about_Remoting for a list of
    fully-serializable types.

    Once I removed “$PSVersionTable.add(“LanguageMode”,$host.Runspace.LanguageMode)” from my profile, all worked as expected.

    Still haven’t found out the “why.”

Leave a Reply

Your email address will not be published. Required fields are marked *