I have the below script in a file called export.ps1 which runs against a text files with user names. The challenge is now I have several files in the same directory called files1.txt,file2.txt,…,filen.txt. I need to do a get-childitem c:\files*.txt and run the below ps script against each one of them in its own Powershell script with passing arguments and variables to each separate running script. Any ideas how to accomplish this? Note that the $date is a variable that will change and I will need to pass to the running scripts.
Add-PSsnapin Microsoft.Exchange.Management.PowerShell.E2010
$users = Get-Content c:\files\file1.txt
$date = “09/01/2015”
foreach ($user in $users) {
$Mailbox = Get-Mailbox -Identity $user
New-MailboxExportRequest -Mailbox $Mailbox -ContentFilter {Received -lt $date} -FilePath \\Server\File1\$Mailbox.pst
}