I'm trying to make a script to return a CSV list of all the .exe and .dll stored in a folder with their name, size and version.
To do so, I'm using this script :
$path = 'C:\MyFolder'
Get-ChildItem -Path $path * -include *.dll,*.exe -Recurse |
Select-Object @{Name = 'Name'; Expression = {$_.Name}},
@{Name = 'Size'; Expression = {$_.Length}},
@{Name = 'Modified'; Expression = {$_.LastWriteTime}},
@{Name = 'ProductVersion'; Expression = {($_.VersionInfo.ProductVersion.ToString())}}
# output on screen
$result | Format-Table -AutoSize
# csv file
$result | Export-Csv -Path 'C:\Users\me\Downloads\softwareVersions.csv' -NoTypeInformation
Unfortunately, some of my files don't have any version, so on the screen, I just see an empty value under the "ProductVersion" column, but because of that, I can't generate my CSV, I get the error :
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null
I tried to replace the concerned line (the one with the version I guess) to try to replace the Version by "Not available" if this information is not found, but I'm a beginner in Powershell code, and it doesn't work... Here's what I tried :
@{Name = 'ProductVersion'; Expression = if(!!$_.VersionInfo.ProductVersion) {'Not available'}else{($_.VersionInfo.ProductVersion)}}
I hope that you have all the needed information, as I'm here to ask your help, code masters :-)
Thanks in advance for your time and your answer!!
Jerome