How Can I run multiple commandlets to generate an output

Hello PowerShellers,

I’m trying to run 4 commandlets on servers in the domain.

I’ve worked out what I want to collect one line at a time. Which is fine.

How can I develop that to run at the same time and produce an output?

This is what I’m running one line at a time:

[pre]

hostname
get-service
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
Get-WmiObject win32_service |ft name, state, startname

[\pre]

To avoid a lot of wasted time and frustration you might start with learning the very basics of Powershell. The free video course from Microsoft Virtiual Academy - Getting Started with Powershell might be good starting point for you.
I thinks it is beyond the scope of this forum to teach you how to do scripting with Powershell.

Yes and I would suggest using below youtube playlist as MVA is getting scrapped from Feb/1/2019

https://www.youtube.com/watch?v=tjxmMioP39k

Something to get you started with below. I don’t know what are the community rules here regarding promoting your own content, but check my LinkedIn profile and you will find a link to a course I have published. One of the sections is creating a server inventory which covers this topic in a lot more details.

 

$servers = Get-Content .\servers.txt # Read a list of servers
$tempCol = @() # Creates an empty array

$ScriptBlock = {

$myObj = "" | Select-Object Hostname, Services, Software, Services2 # Creates a temporary object to store data

$myObj.Hostname = Write-Output $env:COMPUTERNAME # Collect computername
$myObj.Services = get-service # Create a list of services
$myObj.Software = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate # Create a list of software installed
$myObj.Services2 = Get-WmiObject win32_service |ft name, state, startname # Create a list of services again for some reason

return $myObj # return the object
}

$tempCol += Invoke-Command -ComputerName $servers -ScriptBlock $ScriptBlock | Select Hostname, Services, Software, Services2 # Invoke command remotely on all servers and add results to an array
Write-Output $tempCol ## Ouptut the contents of the array

It seems to work. I don’t understand the question.

Thank you for your help.

Hello Edgar,

 

Thank you for your help and for not judging me as a newbie, who needs to review entire courses of material in order to perform a task.

 

I will certainly look at your LinkedIn profile for more information.

 

Kind Regards, Darren