This script work, but it scans all the folders. I only want it to scan for new folder. The folder name are yyyymmdd 20180112
[CmdletBinding()]
param (
[Parameter( Mandatory=$false)]
[string]$SMTPUser=“Outbound@yahoo.com”,
[Parameter( Mandatory=$false)]
[string]$SourcePath="\\internal\ABC\Automation\FTPWorking\IncomingFiles\ABC",
[Parameter( Mandatory=$false)]
[string]$TargetPath="\\internal\ABC\DataAssets\Submissions\ABCD_RAPS\InboundClaimFlatFiles",
[Parameter( Mandatory=$true)]
[string[]]$SearchParameters,
[Parameter( Mandatory=$false)]
[string]$SMTPPass="Xova75672017"
)
#Declaring additional variables
$EmailData = @()
$ReportEmailSubject = “Great news. You received new wonder files from ABCD.”
$SMTPPass = $SMTPPass | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Pass
#…
Modify these Email Settings
#…
$smtpsettings = @{
To = “cohen.carryl@yahoo.com”,"cohen.carryl@gmail.com","cohen.carryl@hotmail.com","cohen.carryl@msn.com"
From = “Outbound@great.com”
Subject = “$ReportEmailSubject - $date”
SmtpServer = “smtp.office365.com”
Credential = $cred
}
Function New-ReportRequest {
[CmdletBinding()]
param(
[Parameter( Position=0,Mandatory=$true)]
[string]$Subject,
[Parameter( Mandatory=$true)]
[array]$Data
)
if ($Data.count -gt '0') {
#Generating HTML Report
$htmlhead="
BODY{font-family: Arial; font-size: 8pt;}
H1{font-size: 18px; color: #419944}
H2{font-size: 14px;}
H3{font-size: 12px;}
TABLE{border: 1px solid black; border-collapse: collapse; font-size: 8pt; margin-left: auto; margin-right: auto}
TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;}
TD{border: 1px solid black; padding: 5px; }
$Subject
Report Created: $now
Total Files Moved: $($Data.count)
"
$htmlbody = $Data | Sort-Object UserName | ConvertTo-Html
$htmltail = "
"
$htmlreport = $htmlhead + $htmlbody + $htmltail
Send-MailMessage @smtpsettings -Body $htmlreport -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8) -UseSsl
}
}
$allFiles = Get-ChildItem -Path $SourcePath -Recurse -Include $SearchParameters
foreach ($file in $allFiles) {
if ($file.Extension -eq “.zip”) {
Expand-Archive -Path $file.FullName -DestinationPath “$SourcePath\Temp” -Force
$subFiles = Get-ChildItem -Path “$SourcePath\Temp” -Include $SearchParameters -Recurse
foreach ($sub in $subFiles) {
Copy-Item -Path $sub.FullName -Destination $TargetPath -Force
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name “SourceFile” -Value $($sub.FullName)
$obj | Add-Member -MemberType NoteProperty -Name “TargetPath” -Value $TargetPath
$EmailData += $obj
}
} else {
Copy-Item -Path $file.FullName -Destination $TargetPath -Force
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name “SourceFile” -Value $($file.FullName)
$obj | Add-Member -MemberType NoteProperty -Name “TargetPath” -Value $TargetPath
$EmailData += $obj
}
}
New-ReportRequest -Subject $ReportEmailSubject -Data $EmailData