Software installation on multiple systems with PowerShell

In this exercise, I will try to install a software on multiple systems with PowerShell, which could reduce some maintenance effort when we need to install or patch some software regularly. The way here is to copy installation file to c:\temp first to remote systems, then install it with remote session, and then check registry and see the installation details.

$computers="computer1","computer2"
	$path="\\server1\sharefolder\TestInstall.msi"
	$computers | where{test-connection $_ -quiet -count 1} | ForEach-Object{ copy-item $path "\\$_\c$\temp" }	

	Invoke-Command { dir c:\temp\TestInstall.msi } -Session $dcs

	$dcs=New-PSSession -ComputerName $computers

	$command =  "msiexec /i 'c:\temp\TestInstall.msi' /qn /l*v c:\temp\TestInstall.log" 
	$scriptblock = [Scriptblock]::Create($command)
	Invoke-Command -ScriptBlock $scriptblock -Session $dcs 

	Invoke-Command {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |Where-Object DisplayName -LIKE '*TestInstall*'| Format-Table AutoSize} -Session $dcs 
	
	Remove-PSSession $dcs