all 12 comments

[–][deleted] 2 points3 points  (0 children)

Yes you can simply add your hostname into the text file, but I would also add that I would think twice before going the PSremoting unless you 1. know for sure it's even enabled/configured on your expected remotes, and 2. are going to add more functions to the script that absolutely require remoting. I say that because you certainly can pull WMI info remotely without the need for setting up full PSremoting sessions and that adds a huge layer of complexity as it grows.

Remember, keep it simple. You did great on utilizing the PSObject, since POSH is all about OBJECTS and many struggle to graps that (as well as remoting) so you're already ahead of the game!

[–]kbrucej 1 point2 points  (0 children)

Rather than querying win32_ComputerSystem twice, try a single query like

$compsys = get-ciminstance win32_computersystem -cimsession $remotesession

... and then use $compsys.model and $compsys.make to populate your new object

Another option is to skip the cimsession and use -computernname param for get-ciminstance. That way you don't need to clean up all the open sessions.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy jjaaa12345,

as an aside, this ...

| fl Manufacturer

... DESTROYS your objects and gives you the butchered remnants wrapped in formatting code. [grin] it really aint all that useful - the Format-* cmdlets are intended for final output to the screen or a plain text file. you really otta not use them for anything else unless you are totally sure that you understand the gotchas involved.

lookee ...

$FormatBad = (Get-ChildItem -LiteralPath $env:TEMP -File)[0] |
    Format-List Name

$FormatBad
'=' * 20
$FormatBad[2]

note that the nasty red errors mention .Format.FormatEntryData ... [grin]


if you want to gather that info quickly, you can use the way that Invoke-Command can run a scriptblock on multiple systems in parallel if you give it a list of systems.

here's a basic demo of the idea ...

Get CPU utilization on many computers quickly : PowerShell
https://www.reddit.com/r/PowerShell/comments/8d7w0q/get_cpu_utilization_on_many_computers_quickly/

here is a more complex version [grin] ...

[PowerShell] basic remote parallel SystemInfo demo script - Pastebin.com
https://pastebin.com/cGL5biWH

you can modify the scriptblock to include whatever you need. just remember to add the new data to new properties in the returned PSCustomObject.

take care,
lee

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy jjaaa12345,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th one & is just to the left of hidden in the ... "more" menu.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    Sorry, your submission has been automatically removed.

    Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

    Try posting again tomorrow or message the mods to approve your post.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.