Mailbox’ların powershell ile yaratılması ve DAG kurulumunun powershell komutları ile nasıl otomatikleştirilebileceğini ya da nasıl yapılabileceğini bu yazıda bulacaksınız.
Aşağıdaki powershell script’ini bir .ps1 uzaktılı dosya yaparak kaydedin.
Add-PSSnapin “Microsoft.Exchange.Management.PowerShell.E2010”
functionSelect-FileDialog
{
param([string]$Title,[string]$Directory,[string]$Filter=”CSV Files (*.csv)|*.csv”)
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | Out-Null
$objForm= New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory =$Directory
$objForm.Filter =$Filter
$objForm.Title =$Title
$objForm.ShowHelp =$true
$Show=$objForm.ShowDialog()
If ($Show-eq”OK”)
{
Return$objForm.FileName
}
Else
{
Exit
}
}
functionCountDown() {
cls
for($Count= 1;$Count-le 100; $Count ++){
Write-Progress -PercentComplete $Count -Activity “Waiting for AD Replication” -Status “Waiting for AD Replication”
Sleep 1
}
}
functionparse_CSVData(){
param(
$FileName
)
$csvFile= Import-Csv $FileName
foreach($DBin$csvFile){
$TSDrivePresent= Test-Path $DB.TransactionLogDrive
if($TSDrivePresent-eq$true){
Write-Host “Transaction Drive is present” -ForegroundColor Cyan
$DBDrivePresent= Test-Path $DB.DatabaseDrive
$TSfldr=$DB.TransactionLogDrive+”\”+$DB.ParentLogFolder
$TSFolderPresent= Test-Path $TSfldr
if($TSFolderPresent-eq$false){
Write-Host “Creating Transaction Log Folder” -ForegroundColor Yellow
New-Item $TSfldr -ItemType Directory
}
if($DBDrivePresent-eq$true){
Write-Host “Database Drive is present” -ForegroundColor Cyan
$DBfldr=$DB.DatabaseDrive+”\”+$DB.ParentDatabaseFolder
$DBFolderPresent= Test-Path $DBfldr
if($DBFolderPresent-eq$false){
Write-Host “Creating Database Folder” -ForegroundColor Yellow
New-Item $DBfldr -ItemType Directory
}
$DBPath=$DBfldr+”\”+$DB.DatabaseName+”.edb”
$LogPath=$TSfldr+”\”+$DB.DatabaseName+”_LOG”
Write-Host “Creating Mailbox Database” -ForegroundColor Blue
New-MailboxDatabase -Name $DB.DatabaseName -Server $DB.PrimaryServer -EdbFilePath $DBPath -LogFolderPath $LogPath
CountDown
Write-Host “Mounting Mailbox Database” -ForegroundColor Green
Mount-Database -Identity $DB.DatabaseName
$DagReplicas=$DB.DAGReplicaServers.Replace(“!”,”`n”);
$ActPrefs=$DB.ActivationPrefs.Replace(“!”,”`n”);
$arr=$DagReplicas.split(“`n”)
$ap=$ActPrefs.split(“`n”)
foreach ($elementin$arr){
foreach ($prefin$ap){
Write-Host “Adding DAG Copies” -ForegroundColor White
Add-MailboxDatabaseCopy -Identity $DB.DatabaseName -MailboxServer $element -ActivationPreference $pref -ErrorActionSilentlyContinue
}
}
}else{
Write-Host “Error: Database Drive Specified is not present” -ForegroundColor Red
}
}else{
Write-Host “Error: Transaction Drive Specified is not present” -ForegroundColor Red
}
}
}
$File=Select-FileDialog -Title “Import an CSV file” -Directory “c:\”
parse_CSVData$File
bu .ps1 uzantılı script’in çalışırken okuyacağı tüm bilgileri içerisinde barındıran bir .csv dosyasına daha ihtiyacımız bulunuyor. Yaratacağınız .csv dosyası içerisinde aşağıdaki bilgiler bulunmalı:
- Database Adı : [DatabaseName]
- Transaction Log Sürücü Adı : [TransactionLogDrive]
- Database Sürücü Adı : [DatabaseDrive]
- Parent Log Klasörü : [ParentLogFolder] (Transaction Log Sürücüsünde)
- Parent Database Klasörü : [ParentDatabaseFolder] (Database Sürücüsünde)
- Primary Server : [PrimaryServer]
- DAG Replica Sunucuları : [DAGReplicaServers] (Her biri ünlem ile ayrılmış, ‘!’)
- Activation Preference [ActivationPrefs] – (Her biri ünlem ile ayrılmış, ‘!’)
Resim-1
Powershell script’iniz hazır. Sunucu ve benzer bilgileri içeren .csv dosyanız hazır. Bu durumda artık parçaları bir araya getirelim.
Aşağıdaki komutu çalıştırın.
.\CreateDAGDatabasesFromCSV.ps1
Resim-2
Çalıştırdığınız komut .csv dosyasının yerini sorduğunda dosyanın yerini gösterin. Dosyanın yerini göstermenizden sonra database’ler, path’ler ve diğer tüm bilgiler kullanılacaktır.
Resim-3
Script’in yaptığı işin tüm Active Directory’ye yayılması için script’in çalışması biraz uzun sürebilir.
Resim-4
Tüm bu adımlardan sonra herşey yolunda gitmiş ise aşağıdaki gibi bir ekran ile karşılaşmanız gerekiyor.
Resim-5
Bu konuyla ilgili sorularınızı alt kısımda bulunan yorumlar alanını kullanarak sorabilirsiniz.
Referanslar