HTTPS clone URL

SSH clone URL

When PowerShell outputs data to the console, the type of that data is not always obvious. That can sometimes lead to frustrating situations. While it's easy enough to check object types manually, it can sometimes be nice to see that information by default. We can accomplish that with a couple slight $profile modifications:

Override Out-Default: The code in typetoggle.ps1 defines a pair of toggle functions. Executing the typeson function will override the Out-Default cmdlet so that it stores output type and length in global variables.

Display prompt information: Within the prompt function of your $profile, use the code from prompt.ps1 to display type information.

The prompt will only display type information if the last command includes a call to Out-Default. This usually occurs implicitly at the end of the PowerShell pipeline.

Examples

Directory listing with 9 items

Last Output Type: System.Object[] (Length: 9)

Single user returned from the ActiveDirectory module's Get-ADUser cmdlet

Last Output Type: Microsoft.ActiveDirectory.Management.ADUser

Results of Get-Content <filename>

Last Output Type: System.Object[] (Length: 44)

Results of Get-Content <filename> -Raw

Last Output Type: System.String (Length: 1327)

Those last two examples really show where something like this can be useful. From the console, the output from both commands appears to be the same. When you check the type, you can see that one command returns an array of 44 strings while the other returns a single 1327-character string. If you're doing any sort of work with that output, that's good information to have.

Acknowledgements

When I realized that this sort of behavior would be useful, I searched around to see how other people had done it. The implementation that came closest to what I wanted was here. So thank you, Andy Schneider, five and a half years after the fact!