Showing posts with label SCOM 2012. Show all posts
Showing posts with label SCOM 2012. Show all posts

Wednesday, April 19, 2017

Adding license to SCOM

System center licensing guide:

http://download.microsoft.com/download/8/9/A/89A3F8B9-94DE-4956-A56E-F6D2B215D0E6/SystemCenter2012R2_Licensing_Guide.pdf

License check commands:

Get-SCOMManagementGroup | ft skuforlicense, version, timeofexpiration –a

Set-SCOMLicense -ProductId "Enter your license key"



Tuesday, February 14, 2017

Microsoft Azure mp configuration for Azure Government cloud

The Microsoft Azure Management pack for SCOM 2012 R2 requires a little different configuration than the commercial cloud. I am going to write down some of the configurations that have to be done.
Link to download the mp:

Install the management pack and import the mp’s in your scom environment. 
The management pack documentation does a fairly good job in explaining the configuration. If you have an user who has read permissions to your Azure active directory and subscription then you can add your Azure subscription using the credentials for the user. But if you have an environment where dual authentication is “enforced” you can use the steps given below. Because apps may not be able receive calls or enter the code in the messages :D

Login to the new portal using your credentials. https://portal.azure.us/
Creating the App for login:
Click Azure Active Directory–App Registrations
Click Add in the top pane and fill up the following parameters for your app.
Name: AnyName [Make a note of this name.]
Application Type: Web App/API
Sign-on URL: http://anyurl  This url does not have to be a working url.
Then click create.
Now select your app under App Registration and in the next blade that opens select Keys.
There is no add button here. If you enter a description for your key then the next values are populated.
Select the expiry duration. As of now the values are 1 year,2 years and Never expires.
Once you hit save then the key value will be displayed.


Important Note:
This will be shown only once so make sure that you copy this key value somewhere safe.

If you have exited then go back to Active directory–App registrations select your app and copy the Application ID from the portal.
Click Active Directory–Domain Names and copy the Name of your domain if you don’t already know it.
These three values App id,domain name,Key will be required when you add your subscription in SCOM.

Now in the portal click on subscriptions. 
Select the subscription you wish to monitor.
Click Access Control in the next blade.
Click Add,select role Reader,Click add users if not already populated. 
In the search under Add users your app would not show up as it shows only users.
Enter the name of your app and click select.Click ok and your app should have reader permissions on your subscription.
Next open the SCOM Operations Console and create a new resource pool in Administration– -Resource Pools called “Azure monitoring resource pool”. 
Add the server that you want to be a member of this pool.

This is recommended because the operations are very resource intensive and if you have a dedicated management server for this pool you will not load the management group.

Navigate to Administration-Microsoft Azure.
Click Add subscription and click the radio button for Service Principal Name.
Remember the three values that i had asked your to copy. You will need them here.
Enter your domain name
Enter the Application ID in the Client ID field.
Enter the key in the password.

Click the advanced box and enter the following values. The forward slash “/” is also required in the ARM Management URI.

Management Service URI: https://management.core.windows.net
Storage Service DNS Suffix: core.usgovcloudapi.net

Your subscription should be populated in the next screen. Select the Azure monitoring server pool.
Next is self explanatory.

After this is done you should be able to see the subscription in
Monitoring–Microsoft Azure–Subscription State.

Now click Authoring and select Microsoft Azure Monitoring Template to configure the resources that you want to monitor.
More about that next time….

Tuesday, December 6, 2016

SCOM DataWare House grooming.

Query to check the size of the tables.

SELECT DB_NAME() AS DbName,
name AS FileName,
size/128.0 AS CurrentSizeMB,
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0 AS FreeSpaceMB
FROM sys.database_files;

Get size of the database.
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
GO

Query to check DW data dates.

Select     min(datetime)as MinDate, max(datetime)as MaxDate ,   datediff(d,min(datetime),max(datetime)) AS NoOfDaysInDataSet from Perf.vPerfHourly

My query showed that there was 424 days of data.

MinDate    MaxDate    NoOfDaysInDataSet
2015-10-09 21:00:00.000    2016-12-06 13:00:00.000    424

Tool for modifying the datawarehouse grooming settings can be downloaded here.

https://blogs.technet.microsoft.com/momteam/2008/05/13/data-warehouse-data-retention-policy-dwdatarp-exe/

Command to run the dwdatarp.exe to get the current sizes of datasets.

C:\temp>dwdatarp.exe -s servername\instancename -d operationsmanagerdw > c:\temp\dwoutput.txt

Dataset name                          Aggregation name     Max Age         Current Size, Kb

Alert data set                             Raw data                           400          104,752 (  0%)
Client Monitoring data set     Raw data                           30              0 (  0%)
Client Monitoring data set     Daily aggregations          400            96 (  0%)
Configuration dataset             Raw data                           400            485,120 (  1%)
DPM event dataset                  Raw data                           400             0 (  0%)
Event data set                           Raw data                           100             12,315,568 ( 14%)
Performance data set              Raw data                           10                4,316,832 (  5%)
Performance data set              Hourly aggregations       400            44,009,336 ( 50%)
Performance data set              Daily aggregations          400            2,049,856 (  2%)
State data set                            Raw data                           180            121,784 (  0%)
State data set                            Hourly aggregations       400           22,979,912 ( 26%)
State data set                            Daily aggregations          400           1,395,216 (  2%)

Changing the grooming settings. Adjust the time according to my reporting requirements.

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "Alert data set" -a "Raw data" -m 180

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "Performance data set" -a "Hourly aggregations" -m 90

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "Performance data set" -a "Daily aggregations" -m 365

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "Event data set" -a "Raw Data" -m 30

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "State data set" -a "Raw data" -m 90

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "State data set" -a "Hourly aggregations" -m 90

dwdatarp.exe -s SERVERNAME\INSTANCENAME -d OperationsManagerDW -ds "State data set" -a "Daily aggregations" -m 90

Monday, October 31, 2016

Using SCOM get-scomalert criteria

The scom alerts for a particular computer can be retrieved by the following commands.

Get-SCOMAlert -ResolutionState 0 | ?{$_.PrincipalName -match 'SQL' -OR $_.PrincipalName -match 'WEB'}

Get-SCOMAlert -Criteria {ResolutionState = 0 and PrincipalName like '%SQL%'  or PrincipalName like '%WEB%'}}

There is significant difference in the time taken for the two commands to be processed.

PS C:\Windows\system32> Measure-Command{Get-SCOMAlert -ResolutionState 0 | ?{$_.PrincipalName -match 'SQL' -OR $_.PrincipalName -match 'WEB'}}
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 604
Ticks : 6047616
TotalDays : 6.99955555555556E-06
TotalHours : 0.000167989333333333
TotalMinutes : 0.01007936
TotalSeconds : 0.6047616
TotalMilliseconds : 604.7616

PS C:\Windows\system32> Measure-Command{Get-SCOMAlert -Criteria {ResolutionState = 0 and PrincipalName like '%SQL%'  or PrincipalName like '%WEB%'}}
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 156
Ticks : 1564777
TotalDays : 1.81108449074074E-06
TotalHours : 4.34660277777778E-05
TotalMinutes : 0.00260796166666667
TotalSeconds : 0.1564777
TotalMilliseconds : 156.4777

The winner is clearly the criteria field. The accepted ones are .

Id
Name
Description
MonitoringObjectId
MonitoringClassId
MonitoringObjectName
MonitoringObjectDisplayName
MonitoringObjectPath
MonitoringObjectFullName
IsMonitorAlert
ProblemId
MonitoringRuleId
ResolutionState
Priority
Severity
Category
Owner
ResolvedBy
TimeRaised
TimeAdded
LastModified
LastModifiedBy
TimeResolved
TimeResolutionStateLastModified
CustomField1
CustomField2
CustomField3
CustomField4
CustomField5
CustomField6
CustomField7
CustomField8
CustomField9
CustomField10
TicketId
Context
ConnectorId
LastModifiedByNonConnector
MonitoringObjectInMaintenanceMode
MonitoringObjectHealthState
ConnectorStatus
NetbiosComputerName
NetbiosDomainName
PrincipalName
AlertParams
SiteName
MaintenanceModeLastModified
StateLastModified

Some more examples using criteria.

Get-ScomAlert -criteria {"Name LIKE 'Failed to connect to computer%' and ResolutionState = 0"}

Get-ScomAlert -criteria {"TimeRaised > '01/03/2017 23:59:00' and ResolutionState != 0"}

$date = $(Get-Date).AddMinutes(-30).ToUniversalTime()
$Alerts = Get-ScomAlert -criteria "ResolutionState = 0 and TimeRaised > '$date'"

Get all new and critical alerts
 $Alerts = Get-SCOMAlert -Criteria {"ResolutionState=0 and Severity=2"};$Alerts

Get all new and warning alerts
 $Alerts = Get-SCOMAlert -Criteria {"ResolutionState=0 and Severity=1"};$Alerts

Get all new and informational alerts
 $Alerts = Get-SCOMAlert -Criteria {"ResolutionState=0 and Severity=0"};$Alerts



Important note: The criteria parameters are case sensitive  so make sure you are using the right one.









 

Wednesday, October 5, 2016

Put Scom Agents and Cluster Servers in Maintenance mode and reboot

Here is a script to put your scom agents including clusters in maintenance mode and rebooting them at a specified time. First you will have to create a task and a management pack in SCOM for rebooting the servers. Link on how to create the management pack is here. https://technet.microsoft.com/en-us/library/hh563486%28v=sc.12%29.aspx?f=255&MSPPError=-2147217396.
Works on System Center Operations Manager 2012 R2.

Create the input files and output files on the locations that you prefer. I have created them in C:\Reboots folder. Add your server names in the input file. Then the script given below can be put in a scheduled task and run at specified times or on demand. You can also run the script manually. Make sure that you modify the maintenance window.

I have not yet added any code to verify and alert if the rebooted servers are not back up.

Will probably do so at a later time. Till then feel free to use this one and modify any way that you like.

#################Script Start ####################################

$RootMS = "RMSName"
$Minutes =  90
$Comment = "Unknown"
#Setting up SCOM connection

Import-Module OperationsManager
$null = New-ScomManagementGroupConnection -ComputerName $RootMS
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorAction SilentlyContinue

$eventLog = New-Object System.Diagnostics.EventLog("Operations Manager")
$eventLog.Source = "Maintenance Mode"

$Servers = GC "C:\Reboots\input.txt"
Function Out($output)
{
Out-File -Filepath "C:\Reboots\output.txt" -InputObject $output -Append
}

Out "###############  Starting Script at $(Get-Date)  ##########################"
foreach($Server in $Servers)
{

$output = "Starting for $Server on $(Get-date)"
Out $output

###Putting the agent and cluster in maintenance mode###########
$agent = Get-ScomAgent | Where-Object { $_.DisplayName –eq $Server -or $_.ComputerName -eq $Server -or $_.PrincipalName -eq $Server }
if(!$agent) { Write-Host "ERROR: $Server is not a monitored system in SCOM." -ForeGroundColor Red; Set-Location $originalPath; return }
$Server = $agent.PrincipalName
$startTime = (Get-Date).ToUniversalTime()
$endTime = $startTime.AddMinutes($Minutes)
if(($clusters = $agent.GetRemotelyManagedComputers())) {
$clusterNodeClass = Get-SCOMClass -Name Microsoft.Windows.Cluster.Node
foreach($cluster in $clusters) {
#$clusterObj = Get-SCOMClass -Name Microsoft.Windows.Cluster | Get-ScomMonitoringObject -Criteria "Name='$($cluster.ComputerName)'"
$clusterobj = Get-SCOMClass -Name Microsoft.Windows.Cluster | Get-SCOMClassInstance | ?{$_.displayname -eq $cluster.ComputerName}
if($clusterObj) {
$clusterObj.ScheduleMaintenanceMode($startTime,$endTime,"PlannedOther",$Comment,"Recursive")
$nodes = $clusterObj.GetRelatedMonitoringObjects($clusterNodeClass)
if($nodes) {
foreach($node in $nodes) {
Out "Putting $node into maintenance mode."
$eventLog.MachineName = $node.Name
$eventLog.WriteEntry("The server entered into maintenance mode $(if($Server -notcontains $node.Name){"on behalf of $Server"}).`r`n`r`nDuration:`t$Minutes minutes`r`nReason:`t$Comment","Information",42)
}
}
}
Out "Putting $($cluster.Computer) into maintenance mode."
New-MaintenanceWindow -StartTime $startTime -EndTime $endTime -MonitoringObject $cluster.Computer -Reason PlannedOther -Comment $Comment
}
}
else {
Out "Putting $Server into maintenance mode."
$eventLog.WriteEntry("The server entered into maintenance mode.`r`n`r`nDuration:`t$Minutes minutes`r`nReason:`t$Comment","Information",42)
New-MaintenanceWindow -StartTime $startTime -EndTime $endTime -MonitoringObject $agent.HostComputer -Reason PlannedOther -Comment $Comment
}
#####Sending commands to the server###########

$Task = Get-SCOMTask -DisplayName "Reboot Computer"
$Overrides = @{Arguments = '"$Target/Property[Type="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/PrincipalName$" "true"'}
$Instance = Get-SCOMClassInstance | ?{$_.Name -eq $agent.name}
Out "Starting task to reboot $($Instance.Displayname) at $(Get-Date)"
Start-SCOMTask -Task $Task -Override $Overrides -Instance $Instance

}

Out "###############  Script Complete at $(Get-Date) #########################"

#################Script End ####################################


I don't take credit for all the scripts that I written. Whenever I can credit the original creators, I do.  If I don't at times please do inform me so that I can include them in the page.

Friday, September 16, 2016

Visual Studio installation failing

Visual Studio 2015 installation failing.


Applies to 2013,2015. OS Windows 8.1

Installation kept failing with the following error in event log.

Faulting application name: vs_professional.exe, version: 14.0.23107.10, time stamp: 0x55414f16

Faulting module name: ntdll.dll, version: 6.3.9600.18233, time stamp: 0x56bb4e1d

Exception code: 0xc0000005

Fault offset: 0x0001dd93

Faulting process id: 0x14a8

Faulting application start time: 0x01d2105f30c9cadb

Faulting application path: C:\Parag\Softwares\VS2015\vs_professional.exe

Faulting module path: C:\WINDOWS\SYSTEM32\ntdll.dll

Report Id: 6e7b1bf9-7c52-11e6-8264-64006a57cea4

Faulting package full name:

Faulting package-relative application ID:

This error was seen in the installation log file located in

C:\Users\Parag\AppData\Local\Temp\dd_vs_professional_20160916160240.log

[1A94:1A98][2016-09-16T15:59:06]e000: Error 0x800705b4: Failed to wait for child to connect to pipe.
[1A94:1A98][2016-09-16T15:59:06]e000: Error 0x800705b4: Failed to connect to elevated child process.
[1A94:1A98][2016-09-16T15:59:06]e000: Error 0x800705b4: Failed to actually elevate.
[1A94:1A98][2016-09-16T15:59:06]e000: Error 0x800705b4: Failed to elevate.

Solution:

Copied the installation files to a local drive from the ISO. Right click the vs_professional.exe. Check the box for Run this program as an administrator.

Then run the exe again.

 


 

 

Friday, September 9, 2016

Audit collection Services

How to determine the Server being used for Audit Collection Forwarding and Collecting.

Open the operations manager console and navigate to Monitoring--Microsoft Audit Collection Services -- Collector or Forwarder. The state view should give you the names of the specific servers.

How to determine the SQL server being used for Audit Collection Database.

  1. Log on to the management server with Administrator permissions.

  2. Click Start, select Run, type regedit in the Open box, and then click OK to start Registry Editor.

  3. Under HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\OpsMgrAC, check the name in  Server value.

Monday, January 5, 2015

Export all rules and monitors with thresholds

Exporting all rules and monitors with thresholds in your SCOM environment.

I found these on the following link

http://technet.microsoft.com/en-us/library/ff723847.aspx


[code language="css"]
##Export all rules

function GetPerfCounterName ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
return ($config.Config.ObjectName + "\" + $config.Config.CounterName)
}

function GetFrequency ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
$frequency = $config.Config.Frequency;

if($frequency -eq $null)
{
$frequency = $config.Config.IntervalSeconds;
}

return ($frequency)
}

function GetDisplayName($performanceRule)
{
if($performanceRule.DisplayName -eq $null)
{
return ($performanceRule.Name);
}
else
{
return ($performanceRule.DisplayName);
}
}

function GetWriteActionNames($performanceRule)
{
$writeActions = "";
foreach($writeAction in $performanceRule.WriteActionCollection)
{
$writeActions += " " + $writeAction.Name;
}
return ($writeActions);
}

$perf_collection_rules = get-SCOMRule # -criteria:"Category='PerformanceCollection'"

$perf_collection_rules | select-object @{name="Type";expression={foreach-object {(Get-MonitoringClass -id:$_.Target.Id).DisplayName}}},@{name="RuleDisplayName";expression={foreach-object {GetDisplayName $_}}} ,@{name="CounterName";expression={foreach-object {GetPerfCounterName $_.DataSourceCollection[0].Configuration}}},@{name="Frequency";expression={foreach-object {GetFrequency $_.DataSourceCollection[0].Configuration}}},@{name="WriteActions";expression={foreach-object {GetWriteActionNames $_}}}  | sort Type,RuleDisplayName,CounterName | export-csv  "C:\Outputs\CollectionRules.csv"

[/code]



[code language="css"]

## Export all monitors

function GetThreshold ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
$threshold = $config.Config.Threshold
if($threshold -eq $null)
{
$threshold = $config.Config.MemoryThreshold
}
if($threshold -eq $null)
{
$threshold = $config.Config.CPUPercentageThreshold
}
if($threshold -eq $null)
{
if($config.Config.Threshold1 -ne $null -and $config.Config.Threshold2 -ne $null)
{
$threshold = "first threshold is: " + $config.Config.Threshold1 + " second threshold is: " + $config.Config.Threshold2
}
}
if($threshold -eq $null)
{
if($config.Config.ThresholdWarnSec -ne $null -and $config.Config.ThresholdErrorSec -ne $null)
{
$threshold = "warning threshold is: " + $config.Config.ThresholdWarnSec + " error threshold is: " + $config.Config.ThresholdErrorSec
}
}

if($threshold -eq $null)
{
if($config.Config.LearningAndBaseliningSettings -ne $null)
{
$threshold = "no threshold (baseline monitor)"
}
}
return $threshold
}
Function GetFrequency ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
$Frequency = $config.Config.Frequency
if($Frequency -eq $null)
{
$frequency = $config.Config.Frequency;
}
return ($frequency)
}
Function GetNumsamples ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
$Samples = $config.Config.Samples
if($Samples -eq $null)
{
$Samples = $config.Config.NumSamples;
}
return ($Samples)
}
Function GetCounterName ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
$Counter = $config.Config.Counter
if($Counter -eq $null)
{
$Counter = $config.Config.CounterName;
}
return ($Counter)
}
Function GetObject ([String] $configuration)
{
$config = [xml] ("<config>" + $configuration + "</config>")
$Object = $config.Config.Object
if($Object -eq $null)
{
$Object = $config.Config.ObjectName;
}
return ($Object)
}
$perfMonitors = get-scommonitor
$perfMonitors | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}},@{name="Target";expression={foreach-object {(Get-SCOMClass -Id:$_.Target.Id).DisplayName}}},DisplayName,enabled,@{name="Threshold";expression={foreach-object {GetThreshold $_.Configuration}}}, @{name="Frequency";expression={foreach-object {GetFrequency $_.Configuration}}}, @{name="Samples";expression={foreach-object {GetNumSamples $_.Configuration}}}, @{name="Counter";expression={foreach-object {GetCounterName $_.Configuration}}}, @{name="Object";expression={foreach-object {GetObject $_.Configuration}}} | sort Target, DisplayName | export-csv "C:\Outputs\PerformanceMonitors.csv"

[/code]

Connecting to SCOM 2012 using powershell

Use the below snippet to connect to your OpsMgr powershell using Windows Powershell ISE.
There after you can use the cmdlets present in SCOM 2012 freely

## Common script for connecting to SCOM 2012 Management Server
$reg = Get-Item "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\SCOM2012PROD\Parent Health Services"
$RMS = $reg.GetValue("NetworkName")
Import-Module -Name OperationsManager
New-SCmanagementGroupConnection $RMS | Out-Null
Write-Host $RMS -foregroundcolor Red
########################################################################################

Wednesday, October 15, 2014

In organizations where you have multiple management groups. And have production environments which need SCOM to be working all the time. Its advisable to have two action accounts in the SCOM environment. When one account's password is near expiry you can switch to another account and change your healthservice to run from that account.
Its a big task to rotate the action accounts on all management groups and this is where my script comes handy. It helps change the default action account on SCOM 2012 and also changes the Data Warehouse Report Deployment Account. The script files are below.
Change the extension to .ps1 after downloading. The usage is given at the top of the scripts.

Om12ActionAccountRotate

Om12ActionAccountpasswordUpdate

Wednesday, September 18, 2013

Manually run partitioning and grooming on SCOM database

The following query if run on the SCOM db will run the grooming on all the partition tables. There are 122 partition tables in SCOM 2012. This will run for each one of them as their Iscurrent value is set to 1.

/*-------------------------------*/

declare @counter int  set @counter = 0  while @counter < 122

begin

exec p_PartitioningAndGrooming

set @counter = @counter + 1

print 'The counter is ' + cast(@counter as char)

end

/*-----------------------------*/