Pulling size and security from io.filesystemwatcher
Posted: Thu Apr 21, 2016 9:22 am
I was wondering if someone could help me with the below script. I would like to add the security and size from the System.IO.NotifyFilters, so that when the results are written to the host and to the csv file, I get the size of the file and the security.
$folder = '\\server\share'
$filter = '*.*'
$fsWatcher= New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true;
NotifyFilter = [System.IO.NotifyFilters]'FileName, LastWrite, Security, Size}
Register-ObjectEvent $fsWatcher Created -SourceIdentifier FinanceFileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
Write-Host "The file '$name' was $changeType at $timeStamp and size is $filesize" -foreground red
Out-File -FilePath D:\Powershell\FileSystemWatcher\outlog-finance.csv -Append -InputObject "The file '$name' was $changeType at $timeStamp and size is $filesize"}
Thanks.
$folder = '\\server\share'
$filter = '*.*'
$fsWatcher= New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true;
NotifyFilter = [System.IO.NotifyFilters]'FileName, LastWrite, Security, Size}
Register-ObjectEvent $fsWatcher Created -SourceIdentifier FinanceFileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
Write-Host "The file '$name' was $changeType at $timeStamp and size is $filesize" -foreground red
Out-File -FilePath D:\Powershell\FileSystemWatcher\outlog-finance.csv -Append -InputObject "The file '$name' was $changeType at $timeStamp and size is $filesize"}
Thanks.