TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Brandon Witcher
NA
1
1k
Powershell need to log when a file is created and owner
Feb 14 2015 9:38 PM
Hello!
I'm a nooby to powershell and trying to create a script that will montor a specific folder for new files.
The tricky part is collecting the owner (or who created it)... is this possible?
I've put some bits and pieces together and here's what I have.
I really need to log who created the files though (also)...
Thank you for any help provided!!
==========================================================
$folder = 'c:\test'
$filter = '*.*'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
Out-File -FilePath C:\Users\BPW\Desktop\newfilelog.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp by $owner"}
# Register-ObjectEvent $fsw Deleted -SourceIdentifier FileDeleted -Action {
# $name = $Event.SourceEventArgs.Name
# $changeType = $Event.SourceEventArgs.ChangeType
# $timeStamp = $Event.TimeGenerated
# Write-Host "The file '$name' was $changeType at $timeStamp" -fore red
# Out-File -FilePath c:\scripts\filechange\outlog.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp"}
# Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action {
# $name = $Event.SourceEventArgs.Name
# $changeType = $Event.SourceEventArgs.ChangeType
# $timeStamp = $Event.TimeGenerated
# Write-Host "The file '$name' was $changeType at $timeStamp" -fore white
# Out-File -FilePath c:\scripts\filechange\outlog.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp"}
=============================================================================
Reply
Answers (
0
)
Print selected rows in multiple crystal report pages in c#
Reporting Service in ASP.NEt Using C#