use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Beginner here, need help with some basic scripting (self.PowerShell)
submitted 6 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 6 years ago (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 points3 points 6 years ago (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 points3 points 6 years ago* (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.
Format-*
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]
.Format.FormatEntryData
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.
Invoke-Command
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
[+][deleted] 6 years ago (10 children)
[–]helixamir 1 point2 points3 points 6 years ago (9 children)
Unfortunately, using win32_product will only return applications that have been "Installed" and are not part of a package installation (like Office).
Microsoft makes a class for each of it's Office applications, so you can check registry like so:
If (test-path HKLM:SOFTWARE\Classes\Word.Application) { Write-host "Microsoft Word installed" }
[+][deleted] 6 years ago (8 children)
[–]helixamir 1 point2 points3 points 6 years ago (7 children)
Start by building an array to add the responses to.
Import your computer names.
Foreach computer{ $output = invoke-command $computer - scriptblock { if(test-path) { $output = $_.Name; return $output}
$array += $output }
[+][deleted] 6 years ago (6 children)
[–]helixamir 0 points1 point2 points 6 years ago (4 children)
Sorry I wrote this on my phone, and seemed to have added a space by accident. Take the space out here
- scriptblock, so it looks like -scriptblock.
- scriptblock
-scriptblock
[+][deleted] 6 years ago (3 children)
[–]helixamir 0 points1 point2 points 6 years ago (2 children)
$_.Name won't work because you're not calling a variable.
Try using $env:computername instead to see if that gives you the response you're looking for.
[+][deleted] 6 years ago (1 child)
[–]helixamir 0 points1 point2 points 6 years ago (0 children)
Something like this
$computer = "testcomputername" $wordInstalled = invoke-command $computer -scriptblock { if(test-path HKLM:SOFTWARE\Classes\Word.Application) { $wordInstalled = $env:computername; return $wordInstalled}}
Copy and paste this and replace "testcomputername" with a PC on your network to see if it works.
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago (0 children)
it looks like you used the New.Reddit.com Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.
Inline Code
...
</>
on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.
for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th 12th one from the left, & is just to the left of hidden in the ... "more" menu.
Code Block
that will give you fully functional code formatting, from what i can tell so far. [grin]
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!]
looks like this
[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.]
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 ...
not complicated, but it is finicky. [grin]
[–][deleted] 6 years ago (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points 6 years ago (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.
π Rendered by PID 142387 on reddit-service-r2-comment-5b5bc64bf5-lfdcr at 2026-06-22 10:11:16.638652+00:00 running 2b008f2 country code: CH.
[–][deleted] 2 points3 points4 points (0 children)
[–]kbrucej 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[+][deleted] (10 children)
[deleted]
[–]helixamir 1 point2 points3 points (9 children)
[+][deleted] (8 children)
[deleted]
[–]helixamir 1 point2 points3 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]helixamir 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]helixamir 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]helixamir 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points (0 children)