2

I need to change default address list in outlook 2010 across thousands of computers. To manually do it in outlook you go to address book>tools>options>and select an address book from the 'When opening the address book, show this address list first:' drop down box.

This is what I have so far:

$outlook = $(New-Object -ComObject Outlook.Application)
$Session = $outlook.Session
$Session.Logon()
$ab = $Session.AddressLists | ? {$_.Name -eq 'Example Address Book')}
$abdialog = $Session.GetSelectNamesDialog()
$abdialog.InitialAddressList = $ab

The error I'm receiving is:

Exception setting "InitialAddressList": "Cannot convert the "System._ComObject" value of type "System._ComObject#{00063049-0000-0000-c000-000000000046}" to type "Microsoft.Office.Interop.Outlook.AddressList"." At line:1 char:1 + $abdialog.InitialAddressList = $Session.AddressLists | ? {$_.name -eq 'BAE Syste ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting

please help I'm going insane with this!

jbockle
  • 633
  • 5
  • 11

1 Answers1

0

I don't know if it's a typo but in :

$ab = $Session.AddressLists | ? {$_.Name -eq 'Example Address Book')}

You should remove the last closing bracket

$ab = $Session.AddressLists | ? {$_.Name -eq 'Example Address Book'}

After that your code works for me.

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
  • sorry yes that was a typo, if $ab is null then the command works properly, can you try replacing 'Example Address Book' with a address list in $Session.AddressLists in your environment to see if it works for you? – jbockle Apr 08 '13 at 12:53