The experience below happens with both PS 5.1 and PS 7 on Win-11\Home.
THE GOAL: For “-ExcludeProperty PSComputerName, RunspaceId” to actually work and omit those values from the ouput. Both of the lines below output the same data.
The second concern, with the same code (above), respectively the output for Pc1 has different values for the ‘Name’ and ‘PSComputerName’ properties; usually they are the same; as evidenced with the Pc2 output. To be clear, Pc1 is outputting an ip for the PSComputerName property-value; instead of the computers’ name. Where should I look to resolve this; in the OS or, PowerShell?
… to resolve what? … that you get an IP instead of the name of the remote computer or the fact that -ExcludeProperty does not seem to work as you expect it - like your subject implies.
@Olaf – Apologies, I’ve updated the original post, you can now see the full code and compare. I incorrectly used the block code, cutting-off the first command-line. I am using the code on the cli.
Both, I was trying to not create separate posts, I’m not sure if both of these issue’s are caused by the code or something else.
@Olaf – I used Invoke-Command with the thought of adding more code to the ScriptBlock, that would include at least two Get-CimInstance call’s from different classes. I am not yet sure which Classes will be used, which is why I stopped here with the -Exclude concern before adding more code, further complicating the trouble-shooting process.
After applying your suggestion I managed to break it again by adding code to the Invoke-Command -ScriptBlock { ... } I’ll mark this thread as resolved.
Since we’re already on it … show your code, show the errors you get and explain what you’re actually trying to do … there might be a better way.
For example:
If you only want to get information about remote systems covered by WMI/CIM you could create CIM-Sessions for the remote computers and run the Get-CimInstance commands against these CIM-Sessions. Quite often that even speeds up the code execution.
@Olaf – Will be pulling data from both the PC running the script and others in the same WorkGroup. The initial post was the beginning of a header or, a pre-script, that would be placed before the main code in a Ps1. With the correction you provided, I’m currently using the following:
With the exception of the 0.00 output for the respective PC name’s, I can live/work with this, until time allows for further research --and learn how to omit the null field for the PC name’s; perhaps using a conditional. I’ll continue and build on the above.
But that’s actually the point I’m trying to make … you may overcomplicate your task …
For example: Just to get the name of the remote computer you don’t need to query Win32_ComputerSystem explicitly. The name of the system is returned by every other WMI-Class as well. So the code you have so far could be boiled down to something like this:
Regardless of that … you should do yourself and others a favor and format your code nicely. To ram it all in one long line just makes it harder to read, to understand and to maintain.
You may read more about style and best practices in the:
@Olaf – I agree, I’m also told I over think things. It’s do to my lack of understanding a certain something. Additional annotation’s below.
Olaf – I’m still struggling, with typo’s and silly syntax error’s like the one you corrected earlier in this thread. I have yet to really research Get-Help *Cim*. The only reason I used it here, is that I remembered your suggestion from another earlier post, about how Get-CimInstance was more efficient/faster than Get-ComputerInfo. This is my first attempt at actually using it beyond a short one-liner.
I do appreciate the version you provided, but I am trying to actually have some code --close to working, before posting a thread. I try real hard not to post queries that appear to ask for free code without showing I put-in some valid effort. I am actually going to buid-out from what I started, as well as, your offering.
Olaf – always did have a problem with that exact point. I feel lucky to have the code resemble the expected output. Once it works, I pretty-much leave well enough alone before I break something, again and again …
Olaf – I hope to get the uninterrupted time to read and absorb its contents.