Ask Your Question
2

How can the lastwritetime be extracted from files located on different shared drives?

asked 2023-06-29 13:05:51 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-29 13:35:02 +0000

djk gravatar image

One way to extract the lastwritetime from files located on different shared drives is to use a PowerShell script. The script would need to loop through the shared drives and folders, and then use the Get-ChildItem cmdlet to retrieve the files and their lastwritetime property.

Here is an example script:

$sharedDrives = "\\server1\share1", "\\server2\share2", "\\server3\share3"

foreach ($share in $sharedDrives) {
    $files = Get-ChildItem -Path $share -Recurse | Where-Object { $_.PSIsContainer -eq $false }

    foreach ($file in $files) {
        $lastWriteTime = $file.LastWriteTime
        Write-Host "File: $($file.FullName) Last Write Time: $lastWriteTime"
    }
}

This script first defines the shared drives as an array of strings. The script then loops through each shared drive and retrieves all files (not directories) within that share using the Get-ChildItem cmdlet with the -Recurse parameter. It then loops through each file and retrieves its lastwritetime property, and outputs the file name and last write time to the console using the Write-Host cmdlet.

Note that the user running the script will need appropriate permissions to access the shared drives and files.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-29 13:05:51 +0000

Seen: 12 times

Last updated: Jun 29 '23