Link to home
Create AccountLog in
Avatar of Pau Lo
Pau Lo

asked on

shares last modified attribute

do file shares on windows servers record a last modified attribute? or just directories?

We have a few servers rammed full of small file shares (which are network home drives) of our users, but some are definately of deleted users in AD. I would love some way of running a script or command against the server for the last modified attribute per "share" (home drive).

One issue is they are hidden shares , i.e. \\fileserver\usera$ reason being on this server are some departmental shares so it keeps the profiles hidden when users are browsing to departmental file shares/directories.
Avatar of josika
josika
Flag of United States of America image

This script will echo every share name as well as date last modified for each shared folder.  You would run this locally on your file server:

 
strServer = "."
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFs = GetObject("WinNT://" & strServer & "/LanmanServer,FileService")
For Each objShare In objFs
	Set oFolder = oFSO.GetFolder(objShare.Path)
	WScript.Echo objShare.Name & " " & oFolder.DateLastModified
Next

Open in new window


You can compare the data with when they were actually modified and make sure everything looks ok.
You can run this one against your file server or other server from a remote machine:


strServer = "us207k3file01"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFs = GetObject("WinNT://" & strServer & "/LanmanServer,FileService")
For Each objShare In objFs
	strPath = "\\" & strServer & "\" & Left(objShare.Path, 1) & "$" & Right(objShare.Path, Len(objShare.Path)-2)
	Set oFolder = oFSO.GetFolder(strPath)
	WScript.Echo objShare.Name & " " & oFolder.DateLastModified
Next

Open in new window

Avatar of Pau Lo
Pau Lo

ASKER

Thanks - hwo can you manually verify the results? in the servers root I cant seem to sort the shares and see a last modified entry as you can a set of directories within the share
Yea - that is how I would do it.  I just meant to double check before you make the script delete anything is all.
Oh, you said you can't see the last modified date?

Just go to where the shares are on the server itself.  I can write the script so that it will tell you the path to the share on the server also if it makes it easier for you.  Even if you hide the share with a '$', then there is still a folder on the server somewhere without that where you can view the data.
Avatar of Pau Lo

ASKER

So a share itself as opposed to a directory also contains a last modified entry - indicating a directory of file within the share has been modified?
This script will tell you where the actual share is on the server itself after the share name.  You can follow that path to see the last modified date on the directory that is shared:

strServer = "us207k3file01"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFs = GetObject("WinNT://" & strServer & "/LanmanServer,FileService")
For Each objShare In objFs
	strPath = "\\" & strServer & "\" & Left(objShare.Path, 1) & "$" & Right(objShare.Path, Len(objShare.Path)-2)
	Set oFolder = oFSO.GetFolder(strPath)
	WScript.Echo objShare.Name & vbTab & objShare.Path & vbTab & oFolder.DateLastModified
Next

Open in new window

I think you may be a little confused.  A share is just a directory on a server or any computers, that is shared.  So basically, you go onto a file server, create a folder where ever you want on the server, right click on it and tell the operating system to Share it.

The only problem is that the root of a share doesn't always contain the latest modified date for every file and folder within it.  To get the true last modified date of every file and folder in the share (directory), you would need to make the script check every single file's and folder's last modified date.

If this is what you want, let me know, I can write that as well.
Avatar of Pau Lo

ASKER

ok thanks for your help, i'll set about running these tommorow and get back to you with any further questions if ok. Yeah that was my issue with the manual verifying, if I go on say explorer and browse to the server, it only shows the visible shares so I cant manually view the last modified for hidden shares. will i need admin rights on that target server to run your scripts?

not being a scripter myself, does I just save it as .vbs and run it from cscript or similar at the command prompt. and where will it write/display the results to?
Yes - you can post question up here, no problem :)

And yes, just save as a .vbs and run it.  You will have to modify the one string in the beginning.  Just put the server name inside the quotes.

strComputer = ""
Avatar of Pau Lo

ASKER

Cool gotcha, and will it require admin rights on target server to get the results? And also, where does it display or write the results out to?
It will most likely require Admin rights for some of the attributes, we can see tomorrow.  Right now I have it echoing the results to the screen, this one will however write the results to c:\log.txt:


strServer = "us207k3file01"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = oFSO.OpenTextFile("c:\log.txt", 2, True)
Set objFs = GetObject("WinNT://" & strServer & "/LanmanServer,FileService")
For Each objShare In objFs
        strPath = "\\" & strServer & "\" & Left(objShare.Path, 1) & "$" & Right(objShare.Path, Len(objShare.Path)-2)
        Set oFolder = oFSO.GetFolder(strPath)
        objFile.WriteLine objShare.Name & vbTab & objShare.Path & vbTab & oFolder.DateLastModified
Next

Open in new window

Oops, didn't close the text file:



strServer = "us207k3file01"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = oFSO.OpenTextFile("c:\log.txt", 2, True)
Set objFs = GetObject("WinNT://" & strServer & "/LanmanServer,FileService")
For Each objShare In objFs
        strPath = "\\" & strServer & "\" & Left(objShare.Path, 1) & "$" & Right(objShare.Path, Len(objShare.Path)-2)
        Set oFolder = oFSO.GetFolder(strPath)
        objFile.WriteLine objShare.Name & vbTab & objShare.Path & vbTab & oFolder.DateLastModified
Next
objFile.Close

Open in new window

Avatar of Pau Lo

ASKER

I really appreciate your help, feedback to you tommorow. Have a great day\night wherever you are from
Avatar of Pau Lo

ASKER

Am a little lost.

If I go (in explorer to) \\fileserver, you can see all the file and print shares listed. but in view > details you just get a name and comments field. this is an XP machine, there is no modified column.

However, if you go into one of the shares, and see the directories, you can then see date modified column.

So what exactly is the script reporting?
To see the modified date of the share, you need to get that info from the file server.  The share is just another directory on the fleserver.
To see the modified date of the share, you need to get that info from the file server.  The share is just another directory on the fleserver.
Avatar of Pau Lo

ASKER

And you cant view that in explorer - it can only be retreived via scripts, whereas directories you can view last modified via view > details

Can you remind me again the rules on last modified. Say I have \\server\homedrive$

and someone edits a file in \\server\homedrive$\theirdocs

Does your script (and the share) report on the last modified for any file within the share? So last modified entry on \\server\homedrive$ will reflect any amendment/access to any file in its child directories?

Sorry if I have asked before just need to get it clear exactly what this script will output.
Ok, when you run this from your XP machine, you can only see the share, not the modified date.  If you log onto your file server and go to the directory where the share is located, you can view the modified date (it's just like any other folder).  This script is getting the modified date from the directory on the file server, not from the share.

I think the modified date on the root directory will only reflect modifications made to files and folder in the level directly below it (this is what I meant when I said the modified date is flaky).  So if you modify \\server\homedrive$\file.txt then it will show the correct modified date at the root directory \\server\homedrive$.  I think if you modify a file located at \\server\homedrive$\Folder\file.txt then the directory called 'Folder' will show the correct modified date but not the root directory \\server\homedrive$.

I can write the script to do this:  check every single file and folder within a every share and find the folder or file that was modified last.  This will be the true last modified date for the entire share.
Avatar of Pau Lo

ASKER

That script would be awesome
Ok, give me a few minutes, out to lunch right now.
Are you running this script from your file server or from a remote machine?
Avatar of Pau Lo

ASKER

My workstation - same domain..
Try this one:


strServer = "FileServer01"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = oFSO.OpenTextFile("c:\log.txt", 2, True)
Set objFs = GetObject("WinNT://" & strServer & "/LanmanServer,FileService")
For Each objShare In objFs
        strPath = "\\" & strServer & "\" & Left(objShare.Path, 1) & "$" & Right(objShare.Path, Len(objShare.Path)-2)
        WScript.Echo strPath
        OldestDate = GetDate(oFSO.GetFolder(strPath))
        objFile.WriteLine objShare.Name & vbTab & objShare.Path & vbTab & OldestDate
Next
objFile.Close
Function GetDate(Path)
	Set oFolder = oFSO.GetFolder(Path)
	For Each file In oFolder.Files
		If file.DateLastModified > GetDate Then GetDate = file.DateLastModified
	Next
	For Each folder In oFolder.SubFolders
		If folder.DateLastModified > GetDate Then GetDate = folder.DateLastModified
		GetDate folder.Path
	Next
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of josika
josika
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Pau Lo

ASKER

darn, general access denied error. WIll ask our IT admin to run it.
Yep, you'll need access to every share and all files in it.