none
Powershell script help for file information RRS feed

  • Question

  • Hello,

    I have a script I am working on, and have run into an issue. It started with me just needing to locate a file or set of files in a location, on computers specified in different OU groups, but has evolved and now they want to add more details to the results such as fileversion, install date, modified date, or whatever property they would like to know. 

    The working version so far returns if the file is located, and the computer host name, as well as the location. 

    How do I add more info such as file version info, etc? 

    $computers = $OUList = @(
    	"ou=OU HERE,dc=DC HERE,dc=DC HERE"
    	"ou=OU HERE,dc=DC HERE,dc=DC HERE"
    "ou=OU HERE,dc=DC HERE,dc=DC HERE"
    
    )
    $computers = $OUList | ForEach-Object {Get-ADComputer -Filter * -Searchbase $_ | Select-Object -ExpandProperty Name}
    $fileNames = Get-Content "C:\Users\PATHTOTEXTFILE\filenamelist.txt"
    $computers | ForEach-Object {
    	$computer = $_
    	$fileNames | Select-Object -Property `
    		@{n='ComputerName'; e={$computer}},
           
    		@{n='FileName'; e={$_}},
    		@{n='Found'; e={Test-Path -Path "\\$($computer)\$($_.Replace(':', '$'))"}}
    } | Export-Csv -NoTypeInformation C:\Users\PATH TO OUTPUT\FoundFiles.csv
    

    The script I found that gives fileversion is this: 

     [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Windows\PATH TO FILE") | Format-List -property *

    I have tried my best to integrate this but I cannot get it to function. Maybe I am going about this wrong. Is there a better way to find files on computers, and select what properties you want to know and have it populate a CSV file? 

    Thanks


    Chris Stambaugh


    • Edited by cstambaugh Tuesday, March 13, 2018 1:36 PM
    • Moved by Bill_Stewart Tuesday, May 8, 2018 7:07 PM This is not "scripts on demand"
    Tuesday, March 13, 2018 10:11 AM

All replies

  • For the next time: could you please chose a subject what already leads to the question you have? "Script help" would fit to almost 99.9999 % of the questions here because it's a scripting forum. ;-)

    To get additional information about a file you can use Get-Item or Get-ChildItem and Select the proper properties. Someting like this:

    Get-item -Path C:\Windows\explorer.exe | 
        Select-Object -Property Name -ExpandProperty VersionInf



    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, March 13, 2018 12:53 PM
  • I edited the title, apologies for that,. In my frustration, I didnt even realize.... 

    I will try to integrate this and see what I can come up with. I was trying to add it to search the list of computers and then the file list, and on first try, a bunch of red.. I will keep at it and see if I can come up with more. 

    Thanks


    Chris Stambaugh

    Tuesday, March 13, 2018 1:39 PM
  • Just as an idea or a blueprint for you to start ... 
    $OUList = @(
        'ou=OU HERE,dc=DC HERE,dc=DC HERE'
        'ou=OU HERE,dc=DC HERE,dc=DC HERE'
        'ou=OU HERE,dc=DC HERE,dc=DC HERE'
    )
    $ComputerList = $OUList | ForEach-Object { Get-ADComputer -Filter * -SearchBase $_ | Select-Object -ExpandProperty Name}
    
    Foreach ($Computer in $ComputerList) {
        $FileName = '\\' + $Computer + '\c$\Windows\explorer.exe'
        If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
            Get-Item -Path $FileName | Select-Object -Property Name, @{Name = 'FileVersion'; Expression = {$_.VersionInfo.ProductVersion}}, LastWriteTime, FullName
        }
        Else {
            $Dummy | Select-Object -Property @{Name = 'Name'; Expression = {'-'}}, @{Name = 'FileVersion'; Expression = {'-'}}, @{Name = 'LastWriteTime'; Expression = {'-'}}, @{Name = 'FullName'; Expression = {$FileName}}
        }
    }
    


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, March 14, 2018 12:16 AM