I mostly been playing with command line and just started to figure out PowerShell. So far I have managed to get this script working with the help of google, but I am unable to figure out how to get the output into an CSV file instead of a text file. It would make things easier for me if I could get it into a CSV and maybe convert into an excel format afterwards. I had seen some commands for that while looking over google results. For starters, how would I get the CSV file working instead of a normal text file?
$Computers = Get-Content 'MachineList.txt' $ProgramList = Get-Content 'ProgramList.txt' $Date = Get-Date -Format MMM-dd-yyyy:HH.mm ForEach ($Computer in $Computers){ # Test connection to remote machine if (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) { # Display a message in the console if no response and output results to the log Write-Host "$Computer" " | " "Offline" " | " "$Date" -ForegroundColor Red -BackgroundColor Black "$Computer" + " | " + "Offline" + " | " + "$Date" | Out-File -FilePath "VerificationLog.txt" -Append } Else { ForEach ($Program in $ProgramList){ # Providing the machine is reachable # Checks installed programs for products that contain provided keywords in the name .\Set-WinRM.ps1 -Mode enable -ComputerName $Computer Function Get-InstalledApps { Invoke-Command -ComputerName $Computer -ScriptBlock { if ([IntPtr]::Size -eq 4) { $Regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' } Else { $Regpath = @( 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' ) } Get-ItemProperty $Regpath | .{Process{If($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName } } $Result = Get-InstalledApps | Where {$_.DisplayName -like "*$Program*"} # Display a message in the console and output results to the log If ($Result) { Write-Host "$Computer" " | " "$Program" " | " "Installed" " | " "$Date" -ForegroundColor Green -BackgroundColor Black "$Computer" + " | " + "$Program" + " | " + "Installed" + " | " + "$Date" | Out-File -FilePath "VerificationLog.txt" -Append } Else { Write-Host "$Computer" " | " "$Program" " | " "NOT Installed" " | " "$Date" -ForegroundColor Yellow -BackgroundColor Black "$Computer" + " | " + "$Program" + " | " + "NOT Installed" + " | " + "$Date" | Out-File -FilePath "VerificationLog.txt" -Append } } .\Set-WinRM.ps1 -Mode disable -ComputerName $Computer # End of Else } # End of ForEach }