Microsoft
Software
Hardware
Network
Question : powershell Get-Acl to Set-Acl system date variable and output to file
Hi
I would appreciate any help on this current script I am testing (sourced in parts from EE and Google) pretty much working to how I require (script example pasted in).
I schedule the script to run daily and grab the ACL from a file and apply it to all files in a defined directory and this all works fine, it also sends an email just to let me know the script has at least run.
What I would like to do is:
1: use a system date variable to only apply the ACL change to files based on the current system date minus 1 day so that only the files with the date previous to the current day's system date have the ACL change applied
2: also if there is a way to output the files that have had the ACL applied sent to a .csv or .log file or even better attached/embedded in the email that is sent?
I have run some searches on EE and Google but cannot seem to find exactly what I am looking for.
I am just starting to look at powershell, so would appreciate any pointers/guidance on this request.
Here's the script example:
(script example START)
$acl = Get-Acl c:\TSTDIR\TD2.txt
$permission = domain\user,FullControl
,Allow
$accessRule = New-Object System.Security.AccessCont
rol.FileSy
stemAccess
Rule $permission
$acl.SetAccessRule($access
Rule)
$acl | Set-Acl c:\TSTDIR\TSTSUB1\*.*
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessag
e
$SmtpClient.Host = "SMTP server"
$mailmessage.from = "
[email protected]
"
$mailmessage.To.add("user@
domain.com
")
$mailmessage.Subject = ***TEST ACL reset complete TEST***
$mailmessage.Body = $(Get-Date -format g)
$mailmessage.Headers.Add("
message-id
", "<3BD50098E401463AA2283778
48493927-1
>")
$smtpclient.Send($mailmess
age)
$mailmessage.IsBodyHtml = 1
(script example END)
Thanks in advance
Bry
Answer : powershell Get-Acl to Set-Acl system date variable and output to file
$FileNameTime = Get-Date -f yyyyMMddHHmm
$fileName = "WhateverYouWant-$FileName
Time"
Random Solutions
... referenced memory at "0x00000000". The memory could not be read".
I'm having email bouncing back undeliverable from one client machine
Windows explorer keeps on reloading my taskbar, shortcuts etc.
Powershell script/snippet to count/subtotal Exchange 2003 mail messages by message class
flash: import a scrollbar component
Want to change browser Address Bar to contain special URI
Excel Macro to Delete Leading Spaces
Cell formatting - #,###.## leaves a hanging decimal point
Cannot send on behalf of the specified user...
Stoping an animated gif from freezing