none
Exchange 2010 EWS view calendar default IPM.Appointment form RRS feed

  • Question

  • Hi, we had a 3rd party add-in that changed everybody's default calendar IPM.Appointment form to IPM.Appointment.MP.  A year or so ago, we ran the EWS script described here:  http://blogs.technet.com/b/heyscriptingguy/archive/2011/12/02/learn-to-use-the-exchange-web-services-with-powershell.aspx to change it back to default.  That worked, however, the form has come back for about 5% of our users.  Rather than run it again against all mailboxes, I would like to identify those mailboxes that have the issue.  So, rather than set these objects, I would like to display the them.  I'm hoping that might help us identify what is different for them and how it came back. I'll paste the code I used from the article to set the property.  I was hoping somebody could give me some guidance as how I could view this property for all mailboxes rather than set it.  Thanks.

    Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"

    $Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials("username","password","domain")
    $exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
    $exchService.Credentials = $Credentials

    $mailboxes = Get-Mailbox

    foreach ($mailbox in $mailboxes) {
    $exchService.AutodiscoverUrl($mailbox.PrimarySmtpAddress)

    $Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchservice,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar)

    $PR_DEF_POST_MSGCLASS_W = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x36E5,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)

    $PR_DEF_POST_DISPLAYNAME_W = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x36E6,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)

    $calendar.SetExtendedProperty($PR_DEF_POST_DISPLAYNAME_W,"Appointment" )
    $calendar.SetExtendedProperty($PR_DEF_POST_MSGCLASS_W,"IPM.Appointment")
    $calendar.Update()

    Thursday, May 29, 2014 4:14 PM

Answers

  • Your passing in a bad  FolderId eg the line

    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$mailbox.PrimarySmtpAddress.ToString())  

    is wrong or missing

    Cheers
    Glen

    • Marked as answer by TracyLW Thursday, July 3, 2014 2:44 PM
    Friday, June 20, 2014 4:03 AM

All replies

  • Try something like this

    ## Load Managed API dll  
    Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"  
      
    ## Set Exchange Version  
    $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2  
      
    ## Create Exchange Service Object  
    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)  
      
    ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials  
      
    #Credentials Option 1 using UPN for the windows Account  
    $psCred = Get-Credential  
    $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())  
    $service.Credentials = $creds      
      
    #Credentials Option 2  
    #service.UseDefaultCredentials = $true  
      
    ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates  
      
    ## Code From http://poshcode.org/624
    ## Create a compilation environment
    $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler=$Provider.CreateCompiler()
    $Params=New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable=$False
    $Params.GenerateInMemory=$True
    $Params.IncludeDebugInformation=$False
    $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
    
    $TASource=@'
      namespace Local.ToolkitExtensions.Net.CertificatePolicy{
        public class TrustAll : System.Net.ICertificatePolicy {
          public TrustAll() { 
          }
          public bool CheckValidationResult(System.Net.ServicePoint sp,
            System.Security.Cryptography.X509Certificates.X509Certificate cert, 
            System.Net.WebRequest req, int problem) {
            return true;
          }
        }
      }
    '@ 
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    
    ## We now create an instance of the TrustAll and attach it to the ServicePointManager
    $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
    
    ## end code from http://poshcode.org/624
      
    ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use  
      
     
    #$uri=[system.URI] "https://casservername/ews/exchange.asmx"  
    #$service.Url = $uri    
      
    ## Optional section for Exchange Impersonation  
      
    #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName) 
    
    $PR_DEF_POST_MSGCLASS_W = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x36E5,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)
    $PR_DEF_POST_DISPLAYNAME_W = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x36E6,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)
    $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) 
    $psPropset.Add($PR_DEF_POST_MSGCLASS_W)
    $psPropset.Add($PR_DEF_POST_DISPLAYNAME_W)
    $mailboxes = Get-Mailbox
    $rptCollection = @()
     
    foreach ($mailbox in $mailboxes) {
    	if($service.url -eq $null){
    		$service.AutodiscoverUrl($mailbox.PrimarySmtpAddress.ToString(),{$true})  
    		"Using CAS Server : " + $Service.url   
    	}
    	Write-Host ("Processing Mailbox " + $mailbox.PrimarySmtpAddress.ToString())
    	$folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$mailbox.PrimarySmtpAddress.ToString())   
    	$Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset)
    	$defMSGClass = $null;
    	$rptobj = "" | Select Mailbox,DefPostSet,Value
    	$rptobj.Mailbox = $mailbox.PrimarySmtpAddress.ToString()
    	$rptobj.DefPostSet = $false;
    	if($Calendar.TryGetProperty($PR_DEF_POST_MSGCLASS_W,[ref]$defMSGClass)){
    		$rptobj.DefPostSet = $true
    		$rptobj.DefPostSet = $defMSGClass
    		Write-Host ($defMSGClass)
    	}
    	$rptCollection+=$rptobj
    }
     
    $rptCollection
    
    Cheers
    Glen

    Friday, May 30, 2014 4:24 AM
  • Thanks Glen, I really appreciate the help.  

    I'm getting close.  I see listing the info I need on the screen as it runs through the script:


    IPM.Appointment

    Processing mailbox mailbox1@address.com

    IPM.Appointment.MP

    Processing Mailbox mailbox2@address.com

    However, I'm still trying to figure out why it has a problem with the $rptobj.DefPostSet = Value  line.  I've tried a couple different things there, but get a similar error to "The term 'value' is not recognized as the name of a cmdlet, function, scipr file, etc....)"

    So the output in the end lists the mailbox names, but the Value column is blank for all.  I'm thinking it's something simple that I'm missing, but so far I'm just not seeing it.


    Monday, June 2, 2014 10:28 PM
  • Sorry that would be because it has a bug that line should have been

    $rptobj.DefPostSet = $defMSGClass

    Cheers
    Glen

    Tuesday, June 3, 2014 4:07 AM
  • Thanks again for the help!  I was on holiday for a couple weeks, just picking it back up again.  Oddly enough, I'm not sure if something in my environment changed or what happened because it doesn't seem happy with the Bind statement now.  I'll paste what I'm seeing below.  I'm still troubleshooting, but would appreciate any suggestions if you have them.

    Exception calling "Bind" with "3" argument(s): "The Id property must be set."
    At line:79 char:2
    +     $Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folder ...
    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ArgumentException
     
    You cannot call a method on a null-valued expression.
    At line:84 char:5
    +     if($Calendar.TryGetProperty($PR_DEF_POST_MSGCLASS_W,[ref]$defMSGClass)){
    +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Thursday, June 19, 2014 3:33 PM
  • Your passing in a bad  FolderId eg the line

    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$mailbox.PrimarySmtpAddress.ToString())  

    is wrong or missing

    Cheers
    Glen

    • Marked as answer by TracyLW Thursday, July 3, 2014 2:44 PM
    Friday, June 20, 2014 4:03 AM
  • Thanks for all the help!
    Thursday, July 3, 2014 2:45 PM