Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Collect file properties from running processes and append to variable for export to CSV

Posted on 2016-08-25
3
Medium Priority
?
72 Views
Last Modified: 2016-08-25
Hi,

I'm trying to export particular meta data from exe files running processes. Ideally everything listed in the VersionInfo tabbed in section., plus the dates. I've been finding PowerShell pretty logical and straight forward so far, but this has me stumped.

I've been trying a whole host of different ways to do this,. And it works if I use out-file, but I'd like the data to be exported as a csv.

I guess I have 2 problems, 1 the Select-Object doesn't seem to access the VersionInfo sub-properties and when ever I try to export it to CSV it fails.

Is there a way of appending objects together, so that they can be handled correctly by the export-csv? Or selecting the data and converting to csv, before appending?

Thank you

$arr = Get-WmiObject Win32_Process -Computer $MachineName  | select ExecutablePath -ExpandProperty ExecutablePath
$data = $null

foreach ($File in $arr)
{
    if (-Not ([string]::IsNullOrWhitespace($file)))
    {
      $Data += Get-ItemProperty -Path $File | Format-list -Property * -Force
      #$Data += Get-ItemProperty -Path $File | Select-Object VersionInfo | ConvertTo-Csv
    }

}

$Data | export-csv $FullPath

Open in new window


This kind of data, but in a single CSV for all files.
VersionInfo       : File:             C:\Windows\system32\taskhostex.exe
                    InternalName:     taskhostex.exe
                    OriginalFilename: taskhostex.exe.mui
                    FileVersion:      6.3.9600.16384 (winblue_rtm.130821-1623)
                    FileDescription:  Host Process for Windows Tasks
                    Product:          Microsoft® Windows® Operating System
                    ProductVersion:   6.3.9600.16384
                    Debug:            False
                    Patched:          False
                    PreRelease:       False
                    PrivateBuild:     False
                    SpecialBuild:     False
                    Language:         English (United States)
CreationTime      : 22/11/2014 12:44:54 PM
CreationTimeUtc   : 22/11/2014 1:44:54 AM
LastAccessTime    : 25/08/2016 1:51:39 PM
LastAccessTimeUtc : 25/08/2016 3:51:39 AM
LastWriteTime     : 22/11/2014 12:44:54 PM
LastWriteTimeUtc  : 22/11/2014 1:44:54 AM
0
Comment
Question by:Dave Scott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41769910
The VersionInfo field has no defined values. For exes, you can usually rely on ProductVersion and FileVersion, but even those are not set for every file. Inother words: you have to pick a list of properties that are likely to be there if you want the resukts to be exported to a common csv.
$ComputerName = $ENV:ComputerName
Get-WmiObject Win32_Process -Computer $ComputerName |
	Select-Object -ExpandProperty ExecutablePath |
	Get-Item |
	Select-Object -Property `
		@{n='ComputerName'; e={$ComputerName}},
		Name,
		DirectoryName,
		@{n='FileVersion'; e={$_.VersionInfo.FileVersion}},
		@{n='ProductVersion'; e={$_.VersionInfo.ProductVersion}},
		@{n='OriginalFilename'; e={$_.VersionInfo.OriginalFilename}},
		@{n='Language'; e={$_.VersionInfo.Language}},
		CreationTime,
		LastWriteTime |
	Export-Csv -Path C:\Temp\ProcessList.csv -NoTypeInformation

Open in new window

1
 

Author Comment

by:Dave Scott
ID: 41769967
Awesome thank you.

I would never have gotten that, I didn't even know that   `    was a character in use in powershell or any different from '
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41769975
The backtick is Powershell's Escape character, and it can be used for line continuation as well.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question