Rui Qiu's Tech Blog
← Back to all posts

February 17, 2017

Find A File with Random Characters and Send Email by SCCM Compliance Rule

Here is my Powershell script for Finding a file with random characters in the end, if the system find the file, it will email to our alert mailbox as well. This is done by SCCM Compliance Rule:

File Finder

Ray Qiu

Feb 15, 2017

Define variables

$username = “myself” $password = ConvertTo-SecureString “password” -AsPlainText -Force $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password $Computer = hostname

Start the scan!

$result=Get-ChildItem C:\Windows\Temp\ | Where-Object {$_.Name -like ‘sam_ref*.wav’} echo $result if($result) { Write-Host “found”

Email the result

Send-MailMessage -From [email protected] -To [email protected] -Subject “SCCM File Found For $Computer” -Credential $cred -Body ” $result Time Stamp: $(Get-Date) Host Name: $Computer ” -SmtpServer exchange.server.address } else { Write-Host “nothing” }