LeVeilleur.net

Subscribe

OpsMgr / SCOM : Automatic Agent Deployment With PowerShell

janvier 20, 2010 By: Christopher Keyaert Category: Scom 2007, powershell

Hello everyone,

Some weeks ago, I had to deploy SCOM Agent on more than 350 windows servers at the time. For that, I wrote a PowerShell Script where you just have to give a server list in input and the name of your RMS/MS . And that’s it, the script is performing the agent installation for you. A CSV file will be generated as output with the agent installation status of each servers.

Concerning the right management, you have to ensure that the Default Action Account using on the server that you will use for deploying the agents (MS normally), has administrative right on the servers that you want to add in SCOM. For that, and the duration of the deployment only, use a Domain Admin Account as the Run As Account of your MS/RMS.

The script :

###########################
# Autor : Christopher Keyaert
# Version : 1.0
# Date : 28 DEC 2009
##########################
#Getting the credential of the user
#$creds = Get-Credential 

###########################
#Param
##########################
$RMS =  #don't forget to use the FQN RMS001.contoso.local
$MS  =  #don't forget to use the FQN MS001.contoso.local

$myFile = "D:\Dep\myfile.txt" #List of Servers
$ResultPath = "D:\Dep" #Folder for path output
Start-Transcript -path "$ResultPath\Transcript$(get-date -uformat '%Y-%m-%d_%Hh%Ms%S').log"

$MaintenanceModeEnable = $false

$MaintenanceModeDuration = 10 * 1440 # 1440 minutes per day
$comment = 'Global Deployment'
$reason = 'PlannedOther'

######################
#Functions
#####################
function SetToMaintenanceMode($rootMS,$computerPrincipalName,$minutes,$comment,$reason)
{
$computerPrincipalName = $computerPrincipalName + ".dir.ucb-group.com"
$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer
$healthServiceClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthService
$healthServiceWatcherClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthServiceWatcher
$computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"
$computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria
$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)
$healthService = $healthServices[0]
$healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'"
$healthServiceWatcher = get-monitoringobject -monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($minutes)

Write-host " "
"Putting " + $computerPrincipalName + " into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment -Reason:$reason

"Putting the associated health service into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthService -comment:$comment -Reason:$reason

"Putting the associated health service watcher into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthServiceWatcher -comment:$comment -Reason:$reason
Write-host " "

}

#################################
#Init the connection to SCOM srv
#################################
if(-not (Get-pssnapin | Where-Object {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client"}))
	{
	Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
	}
new-managementGroupConnection -ConnectionString:$RMS
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin ;
Set-Location $RMS -ErrorVariable errSnapin ;	

##########################
#Agent installation
##########################
#Creating the computers list
$ComputersList  = @()
$ComputersList = Get-Content $myFile

#Define a WindowsDiscoveryConfiguration
$discoConfig = New-WindowsDiscoveryConfiguration –ComputerName: $ComputersList –PerformVerification: $true -ComputerType: "Server" #–ActionAccountCredential: $creds

#Start the discovery process.
$managementServer = Get-ManagementServer | Where-Object {$_.PrincipalName -like "*$MS*"}

$discoResult = Start-Discovery –ManagementServer: $managementServer –WindowsDiscoveryConfiguration: $discoConfig

#Check that the discovery process discovered the Windows computers you specified.
$discoResult.CustomMonitoringObjects

if($discoResult.CustomMonitoringObjects -ne $null)
	{
	Write-Host "Agent installation in progress..."
	Write-Host ""
	Install-Agent –ManagementServer $managementServer –AgentManagedComputer $discoResult.CustomMonitoringObjects

	Write-host "Installation Finished, waiting for 60 secondes"
	Start-Sleep -s 60
	}
else{
	Write-Host "No servers discovered"
	}	

####################################################################
#We have to check if all the agent has been well installed + Maintenance mode
#####################################################################
Write-Host ""
Write-Host "Installation Checking"
Write-Host ""

$InstallArray = @()
foreach($srv in $ComputersList)
	{
	$Value = $null
	$Value = Get-agent | Where-Object {$_.ComputerName -like "*$srv*"}

	if($Value -ne $null)
		{
		Write-Host "$srv - Agent installed "
		$InstallTime = $Value.InstallTime
		$HealthState = $Value.HealthState
		$AgentInstalled = $true

		#Write-Host "Activation of the Maintenance Mode"
		#Put the server in Maintenance Mode
		if($MaintenanceModeEnable -eq $true){SetToMaintenanceMode $RMS $srv $MaintenanceModeDuration $comment $reason}

		}
	else{
		Write-Host "$srv - Agent not installed"
		$AgentInstalled = $false
		$InstallTime = ""
		$HealthState = ""
		}

	$obj = New-Object PSObject
	$obj | Add-Member Noteproperty -Name "Name" -Value $srv
	$obj | Add-Member Noteproperty -Name "AgentInstall" -Value  $AgentInstalled
	$obj | Add-Member Noteproperty -Name "InstallTime" -Value  $InstallTime
	$obj | Add-Member Noteproperty -Name "HealthState" -Value  $HealthState
	$InstallArray += $obj
	}

Write-Host ""
Write-Host "Save the Result File"	

$InstallArray  | Export-Csv "$ResultPath\$(get-date -uformat '%Y-%m-%d_%Hh%Ms%S').csv"
Stop-Transcript

Quoi de neuf dans SCOM R2

janvier 14, 2010 By: Christopher Keyaert Category: Scom 2007

Voici une vidéo en Français expliquant les différences entre SCOM 2007 et SCOM 2007 R2 :

Source

SCOM2007R2 : not enough entropy when installed Linux Agent

décembre 03, 2009 By: Christopher Keyaert Category: Scom 2007

<stdout>Generating certificate with hostname= »xxxxxxxx »
[/home/serviceb/TfsCoreWrkSpcLinux_REDHAT_5.0_x86_64/source/code/tools/scx_ssl_config/scxsslcert.cpp:198]
Failed to allocate resource of type random data: Failed to get random data – not enough entropy
</stdout><stderr>error: %post(scx-1.0.4-248.x86_64) scriptlet failed, exit status 1
</stderr><returnCode>1</returnCode>

<DataItem type= »Microsoft.SSH.SSHCommandData » time= »2009-12-03T12:08:30.6908778+01:00″ sourceHealthServiceId= »91A3B596-F820-6A90-305C-6974DA25966D »><SSHCommandData><stdout>Generating certificate with hostname= »xxxxxxx »
[/home/serviceb/TfsCoreWrkSpcLinux_REDHAT_5.0_x86_64/source/code/tools/scx_ssl_config/scxsslcert.cpp:198]
Failed to allocate resource of type random data: Failed to get random data – not enough entropy
</stdout><stderr>error: %post(scx-1.0.4-248.x86_64) scriptlet failed, exit status 1
</stderr><returnCode>1</returnCode></SSHCommandData></DataItem>

There are two ways to solve this problem, you can recreate the /dev/random file or do a manual agent install.

For both fixes, clean off the partially installed agent using the commands

  1. rpm -e scx
  2. rm -rf /etc/opt/microsoft/scx

Then if you want to make it so that discovery will work from the wizard use the commands

  1. rm /dev/random
  2. mknod -m 644 /dev/random c 1 9
  3. chown root:root /dev/random

A manual install requires copying the appropriate package from %Program Files%\System Center Operations Manager 2007\AgentManagement\UnixAgents to the Unix\Linux machine and installing it directly.

After fixing the install issue, switch the /dev/random file back to a signed random file using the commands:

  1. rm /dev/random
  2. mknod -m 644 /dev/random c 1 8
  3. chown root:root /dev/random

Source : http://blog.xplatxperts.com/xplat-xperts/2009/08/opsmgr-cross-platform-discovery-errors.html

Website is back online

décembre 01, 2009 By: Christopher Keyaert Category: Non classé

Hello guys,

After one month offline due to my moving, my Internet connexion is back now :0)

Enjoy
Christopher

Exchange 2007 : Activate Anti-Spam

octobre 14, 2009 By: Christopher Keyaert Category: Serveur@Home, Windows

Installing Exchange 2007 Anti-spam system

  • Close the EMC (Exchange Management Console).
  • Open the PowerShell and navigate using the following path: « Program Files\Microsoft\Exchange Server\Scripts ».
  • Run the « install-AntispamAgents.ps1″
  • Restart the « Microsoft Exchange Transport » service in order to apply configuration changes.
  • Open the Exchange Management Console, and on the Organization configuration list, select Hub Transport.
  • The « Anti-Spam » tab has been added to the Hub Transport properties.

http://www.petri.co.il/install-anti-spam-exchange-2007.htm