The scenario we are building this script for is that now and then you want to make sure that certain agents have fail-over management servers configured. You also want to make sure that all management servers that are not the primary management server of any selected agent will be in that list of fail-over servers. This would include any new management servers as well as exclude any removed ones. In short, make sure your agent fail-over settings are up-to-date with the current environment.
read more on http://www.teknoglot.se/code/powershell/opsmgr-2012-agent-failover-simple-script-with-wildcards-opsmgr-powershell/
The Copy/Paste Part
As usual, here’s the entire script for you to copy. Read it, try it, adapt it…- # Input SCOM Management Server to connect to in this session
- [string]$inputScomMS = "scomms02.domain.local"
- # Input an existing agent you want to modify
- [string]$inputTargetAgent = "*.domain.local"
- ### Connect to SCOM 2012 Management Group ###
- # Check if OperationsManager module is loaded
- If (Get-Module -Name "OperationsManager") {
- try {
- # Try to load the module
- Import-Module -Name "OperationsManager"
- } catch {
- # Did not work, exit the script
- echo "Could not load Operations Manager module"
- exit
- }
- }
- # Module is loaded, connect to Management Group/Server
- New-SCOMManagementGroupConnection -ComputerName $inputScomMS
- ### END ###
- # Select matching remotely manageable agents
- $scomAgents = Get-SCOMAgent -DNSHostName $inputTargetAgent | Where {$_.ManuallyInstalled -ne $true}
- # Get all management servers
- $scomManagementServers = Get-SCOMManagementServer
- foreach ($scomAgent in $scomAgents) {
- # Get the primary management server for the agent
- $scomPrimaryMS = $scomManagementServers | where {$_.Name -eq $scomAgent.PrimaryManagementServerName}
- # Remove the primary MS from "all MS" array to use it for FailOver servers
- $scomFailOverMS = $scomManagementServers | Where-Object {$_.Name -ne $scomPrimaryMS.Name}
- # Set Primary Management Server
- Set-SCOMParentManagementServer -Agent $scomAgent -PrimaryServer $scomPrimaryMS
- # Set Fail-over Management Server
- Set-SCOMParentManagementServer -Agent $scomAgent -FailoverServer $scomFailOverMS
- }
This posting is provided "AS IS" with no warranties.
No comments:
Post a Comment