私の最終的な目標は、ドメイン内のすべてのユーザーを手動で入力せずに、以下のコードを見つけて実行することですが、方法がわかりません。次に、スクリプトをタスク スケジューラに入れます。
これは、他の誰かを助ける場合に備えて、この背後にあるストーリーと情報です.
私の COO は、グローバル アドレス帳がすべてのデバイス (つまり、Android、IOS、Windows など) にオフラインで表示されることを望んでいます。スティーブ・グッドマンのメソッド/コードを使用して、Exchange Powershell で一度に 1 人のユーザーを実行する方法を見つけました --> http://www.stevieg.org/2012/02/importing-global-address-list-entries-into -a-users-contacts-folder . これを自分のユーザー名に対して行った後、電話で GAL 情報をオフラインで見ることができました。また、誰かが自分の電話から私に電話をかけると、インポートされた GAL から名前を取得することで、私の電話にその人の名前が表示されるようになりました。
基本的に、彼のコードでは、グローバル アドレス帳を個別のアドレス帳として各人にコピーしています。Outlook を見ると、連絡先が表示され、OrgContacts という名前の新しいアドレス帳が表示されます (この場合)。デバイスが次回 Exchange に同期されると、このアドレス帳も同期され、会社全体があなたと一緒になります。数百人のユーザーがいるので、大したことではありません。
これまでに使用したコードは、一度に 1 人のユーザーです。すべてのユーザー名を見つけて実行するのに助けが必要です。実行文字列でワイルドカードを試しましたが、うまくいきませんでした。また、これを達成するためのまったく異なる方法があれば、それも受け入れます。
お時間をいただき、誠にありがとうございました。
各ユーザーのコードを実行するには、これを使用します...
# example (Billy Smith network username is basmith)
.\Copy-OrgContactsToUserContacts.ps1 -Mailbox basmith -FolderName OrgContacts
Exchange パワー シェル コードは次のとおりです...
param([string]$Mailbox,[string]$FolderName="OrgContacts");
#
# Copy-OrgContactsToUserMailboxContacts.ps1
#
# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
# RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
# Parameters
# Mandatory:
# -MailboxFolder : Folder to "own" for these contacts.
#
# Creates s OrgContacts folder in the Mailbox and adds the contacts into it. Does not attempt to
$EwsUrl = ([array](Get-WebServicesVirtualDirectory))[0].InternalURL.AbsoluteURI
$ContactMapping=@{
"FirstName" = "GivenName";
"LastName" = "Surname";
"Company" = "CompanyName";
"Department" = "Department";
"Title" = "JobTitle";
"WindowsEmailAddress" = "Email:EmailAddress1";
"Phone" = "Phone:BusinessPhone";
"MobilePhone" = "Phone:MobilePhone";
}
$UserMailbox = Get-Mailbox $Mailbox
if (!$UserMailbox)
{
throw "Mailbox $($Mailbox) not found";
exit;
}
$EmailAddress = $UserMailbox.PrimarySMTPAddress
# Load EWS Managed API
[void][Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll");
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$service.UseDefaultCredentials = $true;
$service.URL = New-Object Uri($EwsUrl);
# Search for an existing copy of the Folder to store Org contacts
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $EmailAddress);
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot)
$RootFolder.Load()
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $EmailAddress);
$FolderView = new-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)
$ContactsFolderSearch = $RootFolder.FindFolders($FolderView) | Where {$_.DisplayName -eq $FolderName}
if ($ContactsFolderSearch)
{
# Empty if found
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $EmailAddress);
$ContactsFolder = [Microsoft.Exchange.WebServices.Data.ContactsFolder]::Bind($service,$ContactsFolderSearch.Id);
$ContactsFolder.Empty([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete, $true)
} else {
# Create new contacts folder
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $EmailAddress);
$ContactsFolder = New-Object Microsoft.Exchange.WebServices.Data.ContactsFolder($service);
$ContactsFolder.DisplayName = $FolderName
$ContactsFolder.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot)
# Search for the new folder instance
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot)
$RootFolder.Load()
$FolderView = new-Object Microsoft.Exchange.WebServices.Data.FolderView(1000)
$ContactsFolderSearch = $RootFolder.FindFolders($FolderView) | Where {$_.DisplayName -eq $FolderName}
$ContactsFolder = [Microsoft.Exchange.WebServices.Data.ContactsFolder]::Bind($service,$ContactsFolderSearch.Id);
}
# Add contacts
$Users = get-user -Filter {WindowsEmailAddress -ne $null -and (MobilePhone -ne $null -or Phone -ne $null) -and WindowsEmailAddress -ne $EmailAddress}
$Users = $Users | select DisplayName,FirstName,LastName,Title,Company,Department,WindowsEmailAddress,Phone,MobilePhone
foreach ($ContactItem in $Users)
{
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $EmailAddress);
$ExchangeContact = New-Object Microsoft.Exchange.WebServices.Data.Contact($service);
if ($ContactItem.FirstName -and $ContactItem.LastName)
{
$ExchangeContact.NickName = $ContactItem.FirstName + " " + $ContactItem.LastName;
}
elseif ($ContactItem.FirstName -and !$ContactItem.LastName)
{
$ExchangeContact.NickName = $ContactItem.FirstName;
}
elseif (!$ContactItem.FirstName -and $ContactItem.LastName)
{
$ExchangeContact.NickName = $ContactItem.LastName;
}
elseif (!$ContactItem.FirstName -and !$ContactItem.LastName)
{
$ExchangeContact.NickName = $ContactItem.DisplayName;
$ContactItem.FirstName = $ContactItem.DisplayName;
}
$ExchangeContact.DisplayName = $ExchangeContact.NickName;
$ExchangeContact.FileAs = $ExchangeContact.NickName;
# This uses the Contact Mapping above to save coding each and every field, one by one. Instead we look for a mapping and perform an action on
# what maps across. As some methods need more "code" a fake multi-dimensional array (seperated by :'s) is used where needed.
foreach ($Key in $ContactMapping.Keys)
{
# Only do something if the key exists
if ($ContactItem.$Key)
{
# Will this call a more complicated mapping?
if ($ContactMapping[$Key] -like "*:*")
{
# Make an array using the : to split items.
$MappingArray = $ContactMapping[$Key].Split(":")
# Do action
switch ($MappingArray[0])
{
"Email"
{
$ExchangeContact.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::($MappingArray[1])] = $ContactItem.$Key.ToString();
}
"Phone"
{
$ExchangeContact.PhoneNumbers[[Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::($MappingArray[1])] = $ContactItem.$Key;
}
}
} else {
$ExchangeContact.($ContactMapping[$Key]) = $ContactItem.$Key;
}
}
}
# Save the contact
$ExchangeContact.Save($ContactsFolder.Id);
# Provide output that can be used on the pipeline
$Output_Object = New-Object Object;
$Output_Object | Add-Member NoteProperty FileAs $ExchangeContact.FileAs;
$Output_Object | Add-Member NoteProperty GivenName $ExchangeContact.GivenName;
$Output_Object | Add-Member NoteProperty Surname $ExchangeContact.Surname;
$Output_Object | Add-Member NoteProperty EmailAddress1 $ExchangeContact.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1]
$Output_Object;
}