I've often talked about the benefit of including Verbose output in your PowerShell scripts and functions from the very beginning. This is especially helpful when someone else is running your command but encounters a problem. You can have them start a transcript, run your command with –Verbose, close the transcript and send it to you. if you've written informative Verbose messaging you should be able to figure out the problem. Part of the information might include metadata about the person running the command and their environment. To simply things, I've created an easy to use function called Get-PSWho.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
The function writes a custom object to the pipeline with information about the user, their computer and their PowerShell environment. One of the things that might be helpful is knowing where the command is being run as not all PowerShell hosts may support your code.
The other design decision I made was to deviate slightly from the recommended practice of only writing one type of object to the pipeline and not re-inventing the wheel. One of the reasons I wrote this was to make it easy to incorporate into your functions and scripts. You can either embed the function or make sure it is distributed with your commands so that you can include the output in a Write-Verbose line. But, you have to make turn the output into a string.
Write-Verbose "User Metadata" Write-Verbose (Get-PSWho | Out-String)
Since you might need a string anyway, I decided to include it as an option.
Write-Verbose "User Metadata" Get-PSWho -AsString | Write-Verbose
Or you could just as easily pipe the string version to Write-Host. The point is that I thought about how this command might be used and added what I thought would be a useful parameter. Again, I am a bit torn on whether this is the right design decision, but you may simple opt to take my code and paste it into your function directly.
You can find the code on GitHub.
Because I'm using Get-CimInstance, this command won't run in PowerShell Core on non-Windows systems. Although I can probably take that into account and code around it.
If you encounter problems with it or have suggestions, please post an issue on the Gist page.
The current version on GitHub is designed to work with PowerShell Core, although it has not been tested on all platforms.