I have two scripts that run fine as seperate scripts, but when I invoke one from the other then I get this error message:<br>
"Exception Name: System.Management.Automation.MethodInvocationException
Exception Type:
Exception Message: Exception calling "Open" with "3" argument(s): "Could not find a part of the path 'D:\Data Report\'."
The script being called is moving files from "D:\Data Report\ to another folder in the D:\ directory.
I only get this error when I run the script below. Any ideas?
try
{
$folder = "D:\Data Report\" # Enter the root path you want to monitor.
$filter = '*.*' # You can enter a wildcard filter here.
#$scriptPath = {D:\"file_transfer.ps1"}
# In the following line, you can change 'IncludeSubdirectories to $true if required.
$watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $watcher Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
#Call the file_transfer.ps1 script
#Invoke-Expression $scriptPath
Invoke-Expression D:\file_transfer.ps1
}
} # end of try
catch #Catch any fatel errors and send an email with description
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
$ErrorName = $_.Exception.GetType().FullName
$ExceptionBody = @"
Exception Name: $ErrorName
Exception Type: $FailedItem
Exception Message: $ErrorMessage
"@
Send-MailMessage -SmtpServer "server.com" -From "no-replies@company.com" -To "admin@company.com" -Subject "Fatel Error with Monitor Script" -Body $ExceptionBody
} # end of catch
finally
{
}