This script grabs a list of server names from a text file and pings those machines. It then searches for a file on the computers listed in the input file and writes the machinename, filename, filesize, file/productversion and last write time to a .csv. Log file is automatically generated based on the current date and time so this script can be scheduled to run multiple times.


Updated: 19-06-2012



                Script to check files on a range of machines listed in $serverlist. Exports to csv.



                Script to check files on a range of machines listed in $serverlist. The script checks filesize, date modified

                and version of the file and writes this to a comma separated value.



                The plaintext file containing the hostname or full dns names of the computers that should be queried



                The path where the log file is generated. This should be a folder as the file name is automatically generated



                This parameter specifies the specific file for which the information is required. By default this is set to

                netbt.sys. An example of a correct input for this parameter would be: "\c$\WINDOWS\system32\drivers\netbt.sys"



    Name: Get-FileVersion.ps1

    Author: Jaap Brasser

    DateCreated: 19-06-2012






                Get-FileVersion.ps1 -InputFile C:\ListofServers.txt -LogFilePath C:\Log




                The script will query the systems in the C:\ListofServers.txt file details of all the services. The collected results

                will be written to a comma separated file named ''. If the file

                already exists it will be overwritten. Since -PathofFile is not specified the script will default to



#Set variables for script 
    $pathoffile = "\c$\WINDOWS\system32\drivers\netbt.sys" 
# Check parameters 
If (!($inputfile)) {Write-Warning "InputFile not specified, please provide this parameter";returnIf (!($logfilepath)) {Write-Warning "LogFilePath not specified, please provide this parameter";returnIf (!(Test-Path $inputfile)) {Write-Warning "Inputfile not found, exiting";returnIf (!(Test-Path $logfilepath)) {Write-Warning "Logfile path not found, exiting";return} 
# Get server names from file 
$serverlist = @(get-content $inputfile) 
# Gets date and reformats to be used in log filename, enabling automagic log creation 
$tempdate = (get-date).tostring(""$logfile = $logfilepath+"\Autolog_GetFileVersion_"+$tempdate+".csv" 
# Encoding for output is set to utf8, otherwise excel will not open the .csv files correctly 
$exporttofile = "Servername,Filename,Filesize,File Version,Product Version,Last Modified"  
$exporttofile | out-file $logfile -append -encoding utf8  
for ($j=0;$j -lt $serverlist.count;$j++) { 
    #Prepare variables and display progress of script 
    $i = $j + 1 
    $display = $serverlist[$j]+" *** Server "+$i+" out of "+$serverlist.count 
    $testping = test-connection -computername $serverlist[$j-count 1 -quiet 
    # Loop only executed when ping is successful 
    if ($testping) { 
    #Set temporary variable and get file properties 
        $tempfilepath = "\\"+$serverlist[$j]+$PathofFile 
        $tempvar = get-item $tempfilepath -Force 
        #Prepare variables 
        $tempserver = $serverlist[$j] 
        $tempversion = $tempvar.versioninfo 
        #Add information to array that will be written to file at end of script 
        $exporttofile = $tempserver+","+$","+$tempvar.length+","+$tempversion.fileversion+","+$tempversion.productversion+","+$tempvar.lastwritetime 
        $exporttofile | out-file $logfile -append -encoding utf8