Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Can't use -On or -After in simple scripts on diff versions #7

Open
AliRazeghi opened this issue Dec 1, 2014 · 1 comment
Open

Can't use -On or -After in simple scripts on diff versions #7

AliRazeghi opened this issue Dec 1, 2014 · 1 comment

Comments

@AliRazeghi
Copy link

I tried this on Powershell 2 and Powershell 4 on Windows Server 2008 and Windows 7 using different PCs.

This is a sample code:
$EmailUser = 'Test@GMail.Com'
$EmailUser2 = 'Test@Test.Com'
$EmailSubject = "isAlive"
$pw = [System.Convert]::FromBase64String("Base64Password")
$pw = [System.Text.Encoding]::UTF8.GetString($pw)

$secpasswd = ConvertTo-SecureString $pw -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($EmailUser, $secpasswd)
$gmail = New-GmailSession -Credential $mycreds

$inbox = $gmail | Get-Mailbox
$inbox | Get-Message -Before "2014-11-30" ## This works fine.
$inbox | Get-Message -After "2014-11-30" ## This does not work.

Using -After gives us this error:

"Exception calling "Search" with "1" argument(s): "xm003 BAD Could not parse command"
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Gmail.ps\Gmail.ps.psm1:344 char:5

  • $result = $Session.Search('(' + $criteria + ')');
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : Exception
      "

Using -On gives us this error:
GetRFC2060Date : Cannot process argument transformation on parameter 'date'. Cannot convert null to type "System.DateTime".
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Gmail.ps\Gmail.ps.psm1:276 char:44

  •     $imap += 'ON "' + $(GetRFC2060Date $After) + '"'
    
  •                                        ~~~~~~
    
    • CategoryInfo : InvalidData: (:) [GetRFC2060Date], ParameterBindingArgumentTransformationException
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,GetRFC2060Date"
@koladei
Copy link

koladei commented Mar 19, 2016

It appears you have found the problem.
Cannot process argument transformation on parameter 'date'. Cannot convert null to type "System.DateTime"
On line 275 of Gmail.ps\Gmail.ps.psm1
if ($On) {
$imap += 'ON "' + $(GetRFC2060Date $After) + '"'
}
Notice that $After is passed instead of $On
This needs to be corrected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants