Forum

C# Office365 Contac...
 
Bildirimler
Hepsini Temizle

C# Office365 Contacts Alımı Yardım

2 Yazılar
2 Üyeler
0 Reactions
596 Görüntüleme
(@HalilKades)
Gönderiler: 2
Active Member
Konu başlatıcı
 

Merhaba , office365 outlookdan Rehberdeki kişileri çekip Form da listelemem lazım nasıl yapmam lazım daha önce uğraşmış biri varmı acaba ? 🙂

 
Gönderildi : 03/03/2017 13:50

(@umitseyhan)
Gönderiler: 367
Üye
 

Merhaba Halil Bey,

 

Outlook üzeirnden Export/Import yaparak işlemleri gerçekleştirebilirsiniz veya aşağıdaki PS ile mailbox'ın contact bilgilerini alabilirsiniz. Birden fazla mailbox alacaksanız foreach döngüsünü kullanmanız gerekecektir.

 

$MailboxName = "[email protected]"

Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013

$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)

$psCred = Get-Credential
$creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
$service.Credentials = $creds

$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
$service.AutodiscoverUrl($MailboxName,{$true})
"Using CAS Server : " + $Service.url

$ExportCollection = @()
Write-Host "Process Contacts"
$folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Contacts,$MailboxToImpersonate)
$Contacts = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)

$psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$PR_Gender = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(14925,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Short)
$psPropset.Add($PR_Gender)

$ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)
$fiItems = $null
do{
$fiItems = $service.FindItems($Contacts.Id,$ivItemView)
[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)
foreach($Item in $fiItems.Items){
if($Item -is [Microsoft.Exchange.WebServices.Data.Contact]){
$expObj = "" | select DisplayName,GivenName,Surname,Gender,Email1DisplayName,Email1Type,Email1EmailAddress,BusinessPhone,MobilePhone,HomePhone,BusinessStreet,BusinessCity,BusinessState,HomeStreet,HomeCity,HomeState
$expObj.DisplayName = $Item.DisplayName
$expObj.GivenName = $Item.GivenName
$expObj.Surname = $Item.Surname
$expObj.Gender = ""
$Gender = $null
if($item.TryGetProperty($PR_Gender,[ref]$Gender)){
if($Gender -eq 2){
$expObj.Gender = "Male"
}
if($Gender -eq 1){
$expObj.Gender = "Female"
}
}
$BusinessPhone = $null
$MobilePhone = $null
$HomePhone = $null
if($Item.PhoneNumbers -ne $null){
if($Item.PhoneNumbers.TryGetValue([Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::BusinessPhone,[ref]$BusinessPhone)){
$expObj.BusinessPhone = $BusinessPhone
}
if($Item.PhoneNumbers.TryGetValue([Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::MobilePhone,[ref]$MobilePhone)){
$expObj.MobilePhone = $MobilePhone
}
if($Item.PhoneNumbers.TryGetValue([Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::HomePhone,[ref]$HomePhone)){
$expObj.HomePhone = $HomePhone
}
}
if($Item.EmailAddresses.Contains([Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1)){
$expObj.Email1DisplayName = $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].Name
$expObj.Email1Type = $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].RoutingType
$expObj.Email1EmailAddress = $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].Address
}
$HomeAddress = $null
$BusinessAddress = $null
if($item.PhysicalAddresses -ne $null){
if($item.PhysicalAddresses.TryGetValue([Microsoft.Exchange.WebServices.Data.PhysicalAddressKey]::Home,[ref]$HomeAddress)){
$expObj.HomeStreet = $HomeAddress.Street
$expObj.HomeCity = $HomeAddress.City
$expObj.HomeState = $HomeAddress.State
}
if($item.PhysicalAddresses.TryGetValue([Microsoft.Exchange.WebServices.Data.PhysicalAddressKey]::Business,[ref]$BusinessAddress)){
$expObj.BusinessStreet = $BusinessAddress.Street
$expObj.BusinessCity = $BusinessAddress.City
$expObj.BusinessState = $BusinessAddress.State
}
}

$ExportCollection += $expObj
}
}
$ivItemView.Offset += $fiItems.Items.Count
}while($fiItems.MoreAvailable -eq $true)

$fnFileName = "c:\temp\" + $MailboxName + "-ContactsExport.csv"
$ExportCollection | Export-Csv -NoTypeInformation -Path $fnFileName -Encoding UTF8
"Exported to " + $fnFileName

Bilginize.

 

 
Gönderildi : 03/03/2017 19:53

Paylaş: