Question

I have a problem with my PowerShell script. I am trying to check the emails received in my inbox. When an email arrives to the inbox, the script calls a batch file that saves some of the data of the email received in a database. Everything is working perfect when I call the batch file with only strings (test), but when I try to change one of the parameter with the real information I need to save, the batch file is not called. Here is my code.

$MailboxName = "[my address]"
...
Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection($service, 30);
    $stmConnection.AddSubscription($stmsubscription)
    Register-ObjectEvent -inputObject $stmConnection -eventName "OnNotificationEvent" -Action {
        foreach($notEvent in $event.SourceEventArgs.Events){    
            [String]$itmId = $notEvent.ItemId.UniqueId.ToString()
            $message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)
            $name=$message.sender.Name.ToString()
            $arguments= "param1" , "param2"  ,"param3" ,  "param4"  , "param5"  , "param6"   ,"param7" , 1      
            $arguments + (Get-Date) | Out-File c:\temp\log2.txt -Append 
            Start-Process  "spiderT.bat" $arguments 

        } 
        } -MessageData $service
        Register-ObjectEvent -inputObject $stmConnection -eventName "OnDisconnect" -Action {$event.MessageData.Open()} -MessageData $stmConnection
       ...
...

Now, if I change

$arguments= "param1", "param2"  ,"param3" ,  "param4"  , "param5"  , "param6"   ,"param7" , 1   

by

$arguments= $name , "param2"  ,"param3" ,  "param4"  , "param5"  , "param6"   ,"param7" , 1

Looks like is not calling the batch file (the last thing I saw is the log, but not my data in the database). What is happening?

Was it helpful?

Solution

Maybe $name has spaces and that's messing things up? How about if you put $name in double quotes thus:

$arguments= "$name" , "param2"  ,"param3" ,  "param4"  , "param5"  , "param6"   ,"param7" , 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top