Get Last Write Time of a File from Endpoints on a Network

References

PowerShell Gallery | ImportExcel 7.8.4

Overview
  • Gets the last write time of a specified file from a list of devices on a Local Active Directory network.
How to use
  • Replace “FilePath\File.extension” with the path of the file you would like to search
  • Enter a list of device names in the file Endpoints.txt (No Headers are required)
  • Run the script. The output will be stored under the scripts directory. As seen in the example below Export_09082023_1626.

Things to note
  • Requires access to each Endpoints C$ Admin Share. If this is restricted on your network from the account you’re using to run the script, this will not work.
#Automation Get File Version
#Gets a list of hostnames and their specified file version based on the file path configured | Requires access to C$ on specified machines.
#Contact | Josh Woods
#Variables
$Endpoints = Get-Content -Path "$PSScriptRoot\Endpoints.txt"
$File = "FilePath\File.extension"
#Modules
#Excel Module
if (Get-Module -ListAvailable -Name ImportExcel) {
#Import Excel Modules are Installed
Clear-Host
Write-Host "`n"
Write-Host " Import Excel Modules are installed" -ForegroundColor Green
Write-Host "`n"
Start-Sleep -s 2
}
else {
#Install Module
Install-Module -Name ImportExcel -scope CurrentUser -Force
}
#Creating the Output Array
$Array1Output = @()
foreach ($Endpoint in $Endpoints) {
#Write Output
Write-Output "Working on $Endpoint"
#Transform File Path Represent each Host
$File = $File.Replace("C:\","\\$($Endpoint)\C$\")
#Collect Properties
$FileName = Get-ItemProperty $File | Select-object -expandproperty Name
$LastWriteTime = Get-ItemProperty $File | Select-object -expandproperty LastWriteTime
#Output to Output Array (Used for Export)
$Array1 = New-Object PSObject
$Array1 | Add-Member -MemberType NoteProperty -Name 'Endpoint' -Value $Endpoint
$Array1 | Add-Member -MemberType NoteProperty -Name 'FileName' -Value $FileName
$Array1 | Add-Member -MemberType NoteProperty -Name 'LastWriteTime' -Value $LastWriteTime
$Array1Output += $Array1
}
#Export to Excel
$Array1Output | Export-Excel "$PSScriptRoot\Export_$(Get-Date -Format "ddMMyyyy_HHmm").xlsx"