Function: Get-ComputerDetails

Another nice addition for today. In the forums someone asked for retrieving computer information. This information is being retrieved from several WMI objects, and had to be combined in the results. For this PowerShell custom objects are the perfect fit.

The code:

To use it:

Get-ComputerDetails -Computer or01,dc01,ipam01

10 thoughts on “Function: Get-ComputerDetails

  1. Jaap Brasser

    Maybe get rid of the $CustomObject and $result variable as they don’t serve any purpose. Just create the object and let the PowerShell deal with the output.

  2. Steve G

    I’ve tried to use this function. It will run nicely and I can use it – but ONLY from the Windows PowerShell ISE embedded powershell window. This will NOT create a function in ANY other PowerShell process.

    Any ideas on why this might be the case?

    Steve G.

    1. Don Jones

      Steve, are you just running the script in the console? That won’t define a “permanent” function – due to scoping, the function “disappears” when the script finishes. You’ll want to either dot-source the script, or add the function to a Script Module that you can load into the shell. It works in ISE because ISE has a slightly different scope behavior to facilitate development.

    1. Richard Diphoorn Post author

      Mike also notified me on this, and this was my reply to him:

      The “required” line actually comes from the refactoring functionality in ISESteroids; looks like a bug to me that it doesn’t recognise what you described. I will report it back to Tobias Weltner.

      Thanks for noticing. I’ve updated the function and posted it again here: Link

Comments are closed.