System Center build automation with PowerShell

I’ve covered building a full System Center 2012 lab using the PowerShell Deployment Toolkit (PDT) here, here and here. If you want to find out more about PDT, you can check out the Microsoft Building Clouds blog post introducing PDT here.

But what if you have requirements beyond what PDT currently gives you? There are several options available; 1) you can extend the functionality of the PowerShell Deployment Toolkit by editing the Installer PowerShell script and workflow.xml that defines what System Center prerequisites and role features are installed, or 2) you can use the functionally available in PowerShell 4, called Desired State Configuration (DSC), which I blogged about here, that will be available with Windows Server 2012 R2.

Now, I’d like to get more specific about how PowerShell DSC can help you extend the capabilities of the PowerShell Deployment Toolkit and help you further customize and extend your automated System Center build processes. Again, you can custom PDT to include additional functionality, but I do not want fork the development of PDT and choose in this instance to leave PDT unaltered.

This bring us back to using PowerShell Desired State Configuration which will be available in the R2 release of Windows Server 2012 and Windows 8.1. In this use case, I have requirements to install several additional management packs in Operations Manager to allow me to monitor Windows Azure, but directly with the Management Pack for Windows Azure and indirectly using the Global Service Monitor. Install the Windows Azure PowerShell module on the Orchestrator role server, and install an additional connector in Service Manager to sync AD objects back to Service Manager. These are all tasks not performed by PDT presently.

These are proof of concept snippets that can easily be combined into a larger build script. These scripts can be executed from a server, or you can configure DSC in pull mode.

Install the Windows Azure PowerShell module on the System Center Orchestrator server. In this example, the Windows Azure PowerShell module was downloaded and saved to a File Share called \\DC01\Data\Files

$FileShr = “\\DC01\Data\Files”
$SCRoleOr = “SCO01″

Configuration OrchestratorConfig {

param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$NodeName,

[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$FileShr
)

Node $NodeName {

File CopyWAzFile {
Ensure = “Present”
SourcePath = “$FileShr\windowsazure-powershell.0.6.19.msi”
DestinationPath = “C:\SCBuild\windowsazure-powershell.0.6.19.msi”
}

Package InstallWAzPSPackage {
Ensure = “Present”
Path = “C:\SCBuild\windowsazure-powershell.0.6.19.msi”
Name = “Windows Azure PowerShell – August 2013″
ProductId = “D5517EA4-0E8C-4891-8522-1B58AAE4FCA6″
DependsOn = “[File]CopyWAzFile”
}

}
}

## Compile MOFs and Run ##
OrchestratorConfig -NodeName $SCRoleOr -FileShr $FileShr -OutputPath $Pwd\OrchestratorConfig
Start-DscConfiguration -Path $Pwd\OrchestratorConfig -Wait -Force -Verbose -ErrorAction Continue

 

Here is an example of using DSC to install the Active Directory connector in Service Manager

$SCRoleSM = “SCSM01″

Configuration ServiceManagerConfig {

param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$NodeName
)

Node $NodeName {

Script NewScAdConn {
SetScript = {
$SecurePassword = ConvertTo-SecureString -String “Passw0rd!” -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ‘Contoso\!sm_w’, $SecurePassword
$RA = (Get-SCRunAsAccount -DisplayName “Workflow Account”).SecureReference
$DisplayName = “Contoso AD Connector”
$QR = “LDAP://DC=Contoso,DC=com”
New-SCADConnector -DisplayName $DisplayName -Enable $true -QueryRoot $QR -RunAsAccount $RA -ADCredential $Credential
}
GetScript = { Get-SCSMConnector |Where-Object {$_.DisplayName -eq “Contoso AD Connector”} }
TestScript = { ( Get-SCSMConnector |Where-Object {$_.DisplayName -eq “Contoso AD Connector”}).DisplayName -eq “Contoso AD Connector” }
}
}
}

## Compile MOFs and Run ##
ServiceManagerConfig -NodeName $SCRoleSM -OutputPath $Pwd\ServiceManagerConfig
Start-DscConfiguration -Path $Pwd\ServiceManagerConfig -Wait -Force -Verbose -ErrorAction Continue

In Operations Manager, I needed several additional management packs that are not installed by PDT, the Global Service Monitor management pack and the Management Pack for Windows Azure. We also need to install the Alert Attachment management pack needed by GSM and the Windows Identity Foundation Windows feature for Windows Azure. Again, all needed files are located in a central file share. You could also download the files directly from DSC if you wanted to very easily.

$FileShr = “\\DC01\Data\Files”
$SCRoleOr = “SCOM01″

Configuration OperationsManagerConfig {

param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$NodeName,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$FileShr
)

Node $NodeName {

WindowsFeature WinIdentFoundFeature {
Ensure = “Present”
Name = “Windows-Identity-Foundation”
}

File CopyGSMMPFile {
Ensure = “Present”
SourcePath = “$FileShr\System%20Global%20Service%20Monitor.msi”
DestinationPath = “C:\SCBuild\System%20Global%20Service%20Monitor.msi”
}

Package InstallGsmMP {
Ensure = “Present”
Path = “C:\SCBuild\System%20Global%20Service%20Monitor.msi”
Name = “System Global Service Monitor”
ProductId = “201038BE-5725-43ED-B696-098C450D225B”
DependsOn = “[File]CopyGSMMPFile”
}

Script ImportGsmLibMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Global Service Monitor\Microsoft.SystemCenter.Omonline.OutsideIn.Library.mp”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.Omonline.OutsideIn.Library”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.Library”}).Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.Library”) }
DependsOn = “[Package]InstallGsmMP”
}

Script ImportGsmUiMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Global Service Monitor\Microsoft.SystemCenter.Omonline.OutsideIn.UI.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.Omonline.OutsideIn.UI”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.UI”}).Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.UI”) }
DependsOn = “[Script]ImportGsmLibMP”
}

Script ImportGsmDscMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Global Service Monitor\Microsoft.SystemCenter.Omonline.OutsideIn.Discovery.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.Omonline.OutsideIn.Discovery”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.Discovery”}).Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.Discovery”) }
DependsOn = “[Script]ImportGsmUiMP”
}

Script ImportGsmInfraMonMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Global Service Monitor\Microsoft.SystemCenter.Omonline.OutsideIn.InfrastructureMonitoring.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.Omonline.OutsideIn.InfrastructureMonitoring”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.InfrastructureMonitoring”}).Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.InfrastructureMonitoring”) }
DependsOn = “[Script]ImportGsmDscMP”
}

Script ImportGsmVSWebMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Global Service Monitor\Microsoft.SystemCenter.Omonline.OutsideIn.VSWebTest.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.Omonline.OutsideIn.VSWebTest”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.VSWebTest”}).Name -eq “Microsoft.SystemCenter.Omonline.OutsideIn.VSWebTest”) }
DependsOn = “[Script]ImportGsmInfraMonMP”
}

Script ImportGsmWebAppTestMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Global Service Monitor\Microsoft.SystemCenter.WebApplicationTest.External.Library.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.WebApplicationTest.External.Library”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.WebApplicationTest.External.Library”}).Name -eq “Microsoft.SystemCenter.WebApplicationTest.External.Library”) }
DependsOn = “[Script]ImportGsmVSWebMP”
}

File CopyAAMPFile {
Ensure = “Present”
SourcePath = “$FileShr\Microsoft.SystemCenter.AlertAttachment.mpb”
DestinationPath = “C:\SCBuild\Microsoft.SystemCenter.AlertAttachment.mpb”
}

Script ImportAltAttchMp {
SetScript = { Import-SCOMManagementPack “C:\SCBuild\Microsoft.SystemCenter.AlertAttachment.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.AlertAttachment”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.AlertAttachment”}).Name -eq “Microsoft.SystemCenter.AlertAttachment”) }
DependsOn = “[File]CopyAAMPFile”
}

File CopyWAzMPFile {
Ensure = “Present”
SourcePath = “$FileShr\System%20Center%202012%20Management%20Pack%20for%20Windows%20Azure.msi”
DestinationPath = “C:\SCBuild\System%20Center%202012%20Management%20Pack%20for%20Windows%20Azure.msi”
}

Package InstallWAzMP {
Ensure = “Present”
Path = “C:\SCBuild\System%20Center%202012%20Management%20Pack%20for%20Windows%20Azure.msi”
Name = “System Center 2012 Management Pack for Windows Azure”
ProductId = “2CAB00CB-305E-4C7C-922D-2B00EA2A16AE”
DependsOn = “[File]CopyWAzMPFile”
}

Script ImportWazMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Center 2012 Management Pack for Windows Azure\Microsoft.SystemCenter.WindowsAzure.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.WindowsAzure”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.WindowsAzure”}).Name -eq “Microsoft.SystemCenter.WindowsAzure”) }
DependsOn = “[Package]InstallWazMP”
}

Script ImportWazDashMp {
SetScript = { Import-SCOMManagementPack “C:\Program Files (x86)\System Center Management Packs\System Center 2012 Management Pack for Windows Azure\Microsoft.SystemCenter.WindowsAzure.Dashboard.mpb”}
GetScript = { Get-SCOMManagementPack -Name “Microsoft.SystemCenter.WindowsAzure.Dashboard”}
TestScript = { ((Get-SCOMManagementPack |Where-Object {$_.Name -eq “Microsoft.SystemCenter.WindowsAzure.Dashboard”}).Name -eq “Microsoft.SystemCenter.WindowsAzure.Dashboard”) }
DependsOn = “[Script]ImportWazMP”
}

}
}

## Compile MOFs and Run ##
OperationsManagerConfig -NodeName $SCRoleOM -FileShr $FileShr -OutputPath $Pwd\OperationsManagerConfig
Start-DscConfiguration -Path $Pwd\OperationsManagerConfig -Wait -Force -Verbose -ErrorAction Continue

PowerShell Desired State Configuration (DSC) is turning into one of the killer new features in PowerShell 4, and combined with the PowerShell Deployment Toolkit (PDT) you can quickly stand up new System Center environments for lab, POC and even production deployments.

If you attended System Center Universe, you might also get the idea that with PowerShell Workflow, you could complete orchestrate the process of building your System Center based private, hybrid or even public cloud!.

2 thoughts on “System Center build automation with PowerShell

Leave a Reply