X
GO
Blog
16Mar

DSC myAdExchPrepareSchema.psm1

Blog Writer | DSC, Exchange, PowerShell | Exchange Server | | View Counts (517) |Return|
0 ( 0 reviews)
|

How to Exchange Prepare Schema with PowerShell DSC

During some automatized deployments, as often, we have to deploy Microsoft Exchange 2016 automatically.

 

The well-known module https://www.powershellgallery.com/packages/xExchange/ does many things, but no Exchange preparation on a fresh AD.

Here is a simple DSC Code which

  • checks if AD schema is at the right version
  • if not, launch Exchange setup with the correct parameters

Code

Import-Module $PSScriptRoot\..\myAdHelper.psm1 -Verbose:$false
function Get-TargetResource
{
    param
 (
  [System.String]$ExchSchemaVersion,
  [parameter(Mandatory = $true)]
  [System.String]$Path,
  [parameter(Mandatory = $true)]
  [System.String]$Arguments,
  [System.Management.Automation.PSCredential]$Credential
    )
 $Schema = ReplacePartitionTokens -Identity "%%schema%%" -Credential $Credential
 myGetAdObject -Identity "CN=ms-Exch-Schema-Version-Pt,$Schema" -Credential $Credential -Properties @('rangeUpper')
 
}

function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
  [System.String]$ExchSchemaVersion,
  [parameter(Mandatory = $true)]
  [System.String]$Path,
  [parameter(Mandatory = $true)]
  [System.String]$Arguments,
  [System.Management.Automation.PSCredential]$Credential
    )
 
 StartAndWaitWaitForProcessEnd -Path $Path -Arguments $Arguments -Credential $Credential -Delay 7200 -Verbose -TaskName 'EXCHANGE - PrepareSchema' -ProcessToWaitFor 'ExSetup*'
 
}

function Test-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
  [System.String]$ExchSchemaVersion,
  [parameter(Mandatory = $true)]
  [System.String]$Path,
  [parameter(Mandatory = $true)]
  [System.String]$Arguments,
  [System.Management.Automation.PSCredential]$Credential
    )
 $Result = $true
 
 $Version = Get-TargetResource @PSBoundParameters
 
 if ($Version)
 {
  if ([uint32]$Version.rangeUpper -lt [uint32]$ExchSchemaVersion)
  {
   $Result = $false
  }
 }
 else
 {
  $Result = $false
 }
 
 $result
}
Export-ModuleMember -Function *-TargetResource

Module Call

    myAdExchPrepareSchema ExchangePrepareSchema
    {
     ExchSchemaVersion = '15317'   #CU3 15326
     Path = "$($ConfigurationData.Binaries.Exchange2016)\Setup.exe"
     Arguments = '/PrepareSchema /IAcceptExchangeServerLicenseTerms'
     Credential = $DscCredentials
     DependsOn = @('[xPendingReboot]BeforeExchangePreparation')
    }

Related

Hard to replicate Exchange Connectors

When you have multiple Microsoft Exchange Servers receiving emails, you have to create exactly the s...

How to sign XML file with PowerShell

It often happened in my developments to have to protect my sources, and be sure that the configurati...

Bulk Deploy Microsoft Windows Nano Server 2016 and join domain

As I searched the web how to automatically deploy NANO server and join it to Active Directory, I cou...

Authenticating users with smartcard and login/password

When a user opens an Active Directory session with his smartcard, it happens that some applications ...

Categories
Tags
Popular
  • Recent
  • Popular
  • Tag