Gmail.ps
Gmail.ps copied to clipboard
Can't use -On or -After in simple scripts on diff versions
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 = '[email protected]' $EmailUser2 = '[email protected]' $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"
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.