Windows file proper...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

[Closed] Windows file properties - showing the owner

16 Posts
6 Users
0 Reactions
83 Views
Posts: 13369
Full Member
Topic starter
 

I asked for what I thought was a simple script.

Input = A directory name
Output = A file containing each filename in that directory with the Owner, size and date last used
Bonus points = If you can get it to do the full subdirectory structure as well

Apparently Owner is an ACL property so not as simple as the others.

Are my team missing something, surely this kind of script must exist somewhere or be relatively easy to write to run on a windows machine.

Suggestions please


 
Posted : 08/01/2021 1:30 pm
Posts: 8819
Full Member
 

$Path = "c:\test"
$LogPath = "c:\test"
$User = "Domain\user"
Get-ChildItem $Path -force -Recurse |
Select Name,Directory,Length,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},@{Name="MB";Expression={$_.Length / 1MB}},CreationTime,LastAccessTime |
Where Owner -eq $User |
Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation

Internet provided. May or may not work.


 
Posted : 08/01/2021 1:37 pm
Posts: 77347
Free Member
 

^^ that works with a couple of tweaks. The quote marks are busted (probably forum formatting) and you're filtering by a specific owner which isn't required.

Here. Obviously, you'll need to change the pathnames.

$Path = "C:\test"
$LogPath = "C:\test"
Get-ChildItem $Path -force -Recurse |
Select Name,Directory,Length,@{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}},@{Name="MB";Expression={$_.Length / 1MB}},CreationTime,LastAccessTime |
Export-Csv $LogPath\FileFolderOwner.csv -NoTypeInformation

 
Posted : 08/01/2021 2:01 pm
Posts: 12072
Full Member
 

dir /s /q /ta >output_file_name.log

Edit: stick it in a "x.bat" file, and pass %1 just after the dir as an argument:

dir %1 /s /q /ta >output_file_name.log


 
Posted : 08/01/2021 2:03 pm
Posts: 77347
Free Member
 

Oh yeah,

Are you comfortable running PowerShell scripts or do you need guidance here?


 
Posted : 08/01/2021 2:06 pm
Posts: 12072
Full Member
 

Are my team missing something, surely this kind of script must exist somewhere or be relatively easy to write to run on a windows machine.

I'm guessing your team are all under 30 and have never used the command line... I fire it up every now and then on video calls just to scare them 😀


 
Posted : 08/01/2021 2:07 pm
Posts: 12072
Full Member
 

Are you comfortable running PowerShell scripts or do you need guidance here?

My effort runs in a normal CMD (dos) shell.


 
Posted : 08/01/2021 2:08 pm
Posts: 77347
Free Member
 

dir /s /q /ta >output_file_name.log

That'll show you the Last Accessed user, not the file owner?

If you want to do it in CMD it's probably a job for wmic.


 
Posted : 08/01/2021 2:08 pm
Posts: 12072
Full Member
 

That’ll show you the Last Accessed user, not the file owner?

The q switch is the owner.


 
Posted : 08/01/2021 2:14 pm
Posts: 77347
Free Member
 

The q switch is the owner.

Well bugger me, I missed that. Nice.


 
Posted : 08/01/2021 2:15 pm
Posts: 8613
Full Member
 

We use TreeSize for this sort of thing - much better than a script


 
Posted : 08/01/2021 2:17 pm
Posts: 12072
Full Member
 

We use TreeSize for this sort of thing – much better than a script

Dunno, I'm a big fan of quick and dirty scripts. If I use them more than once I stick them in a directory that on my custom path, after a while I've built up a small library of simple utilities that I use all the time. But yeah, anything more complex and they do soon show their limits.

I've mean meaning to learn Powershell for ages, but as I don't have admin rights on my work machine there's not much point - all the interesting extra bits of funcionality aren't available.


 
Posted : 08/01/2021 2:25 pm
Posts: 13369
Full Member
Topic starter
 

Thanks all - team happy and now focussed on service account and security challenges. None of them thought about the command line options. Kids today huh?


 
Posted : 08/01/2021 2:51 pm
Posts: 77347
Free Member
 

I’ve mean meaning to learn Powershell for ages

As have I. I know the basics but (ironically here as I missed it completely) not to anything like the degree that I know command line.


 
Posted : 08/01/2021 5:56 pm
Posts: 25815
Full Member
 

doesn't format:C work any more ?
😉


 
Posted : 08/01/2021 8:28 pm
Posts: 12072
Full Member
 

doesn’t format:C work any more ?

Never did, it's format c: 🙂


 
Posted : 08/01/2021 8:30 pm
Posts: 25815
Full Member
 

Didn't want to type the real thing in case there was an accident of some global standing 😀


 
Posted : 08/01/2021 8:31 pm

6 DAYS LEFT
We are currently at 95% of our target!