diff --git a/powershell/README.md b/powershell/README.md new file mode 100644 index 0000000..4d10a17 --- /dev/null +++ b/powershell/README.md @@ -0,0 +1,3 @@ +# Powershell + +使用powershell语言编写的脚本 diff --git a/powershell/监控文件夹变换.ps1 b/powershell/监控文件夹变换.ps1 new file mode 100644 index 0000000..0466ac6 --- /dev/null +++ b/powershell/监控文件夹变换.ps1 @@ -0,0 +1,28 @@ +# ҪصļУļбȴڡ +$folder = 'D:\images\' +# ÿμصļʱ䣬ʱΪ1000룬1 +$timeout = 1000 +# ļϵͳӶ +$FileSystemWatcher = New-Object System.IO.FileSystemWatcher $folder +# ļµļ +$FileSystemWatcher.IncludeSubdirectories = $true; +# ˼صļ +$FileSystemWatcher.Filter = "*.as*"; +Write-Host CTRL+C ˳ļ $folder ļء +while ($true) { + # ļڵб仯 + $result = $FileSystemWatcher.WaitForChanged('all', $timeout) + if ($result.TimedOut -eq $false) + { + # ļеݱ仯ʱʾ + Write-Warning ('File {0} : {1}' -f $result.ChangeType, $result.name) + $title = ('File {0} : {1}' -f $result.ChangeType, $result.name) + $body = ('File {0} : {1}{2}' -f $result.ChangeType, $folder,$result.name) + # (Get-Credential).password | ConvertFrom-SecureString > mpass.txt ļsmt֤û + $pw = Get-Content .\mpass.txt | ConvertTo-SecureString + $cred = New-Object System.Management.Automation.PSCredential "noreplay@test.com", $pw + Send-MailMessage -To yaokuaile@kaihejia.com -from "ļ " -Subject "$title" -Body "$body" -encoding ([System.Text.Encoding]::UTF8) -priority High -smtpServer smtp.test.com -Credential $cred; + + } +} +Write-Host 'رȡ.' \ No newline at end of file