Hi all,
I created a Powershell that would export users’s information from Forest 1, Would created a mapped drive in a second forest DC then copy the exported CSV File to it.
Then it would import those users’s info as contacts and publish them to GAL. The powershell works fine but my problem is that in order to get the contacts published to GAL i’ll have to enter two values in a “showaddressbook” attribute which is passed remotely to the second forest’s powershell in a $addressbook variable …
The error I get when I run this powershell script is “Invalid type ‘System.Collections.ArrayList’.
Parameter name: ShowInAddressBook”
Without the showaddressbook value the script works fine. it’s just that it has two values instead of one.
I would appreciate any help. thanks
Code “Import-Module ActiveDirectory”
"
$targetComputer = “adlab.lab.com”
$AddressBook = “CN=All Contacts,CN=All Address Lists,CN=Address Lists Container,CN=lab,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=lab,DC=com”,“CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=lab,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=lab,DC=com”
$Path = $env:username + “csvfiles.csv”
$encrypted = “01000000d08c9ddf0115d1118c7a00c04fc297eb0100000028a8653db5616e4ba09a8cbc702f25690000000002000000000003660000c000000010000000e22ad9548aa4abeea00e7d6dc2eb97050000000004800000a00000001000000059565d2dd3ad10cf83e9c70c5674d5f010000000f33a20cc4b1dd36c36e71b1cbe18af4614000000b0323e8c35fbd60d18e5e16f11801315f957b154”
$user = “lab\administrator”
$password = ConvertTo-SecureString -string $encrypted
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$password
$parentOU = “OU=All Contacts,DC=lab,DC=com”
$newOU = “OU=Dogus Holding,$parentOU”
#=======================Export Mail Enabled Users=======================#
Get-ADUser -filter * -properties * | ?{($.emailaddress -ne $null) -and ($.enabled -eq “True”)} | Select displayName, EmailAddress,name,SamAccountName | Export-Csv C:\exported1.csv -NoTypeInformation
Import-csv c:\exported1.csv | Select-Object *,@{Name=“Addressbook”;Expression={“$AddressBook”}} | Export-Csv $Path -NoTypeInformation
$session = New-PSSession -ComputerName $targetComputer -Credential $cred
Invoke-command $session -ArgumentList $newpath,$newOU -ScriptBlock {Param($X,$Y) Import-CSV $X | foreach {New-ADObject -Type Contact -Name $.Name -otherattributes @{“displayName”=$.displayName;“mail”=$.EmailAddress;“proxyAddresses”="SMTP:$($.EmailAddress)";“targetaddress”=$.EmailAddress;“givenName”=$.name;“msRTCSIP-PrimaryUserAddress”=$.EmailAddress; “msRTCSIP-UserEnabled”=$true; ‘showinaddressbook’ = $.AddressBook; “mailnickname”=$_.SamAccountName } -Path $Y } }
"