Wednesday 7 November 2012

Install MSMQ Role Services (features) using PowerShell

In continuation of my quest to automate everything, here is a script to automate the installation of MSMQ role services (features)

 import-module servermanager
 
 $windowsfeatures = @("MSMQ", "MSMQ-Services", "MSMQ-Server", "MSMQ-Directory", "MSMQ-Triggers", "MSMQ-HTTP-Support")
 
 foreach ($feature in $windowsfeatures)
 {
 
 $state = Get-WindowsFeature -Name $feature.trim()
 
  if ($state.Installed -eq $true)
  {
   Write-Host "$feature is already installed"
  }
  else
  {
   Write-Host "Installing $feature"
 
   $result = add-windowsfeature $feature.trim()
 
   if (([System.Convert]::ToBoolean($result.Success)))
   {
    Write-Host "$feature has been installed"
   }
   else
   {
    Write-Host "An error occurred installing $feature"
    exit
   }
  }
 }
 
 Write-Host "All Role Services have been Installed"
 
 remove-module servermanager
 
  

No comments:

Post a Comment