Documentation forServer Configuration Monitor
Monitoring server configurations is a key capability of Hybrid Cloud Observability Advanced and is also available in a standalone module, Server Configuration Monitor (SCM). Hybrid Cloud Observability Advanced and SCM are built on the self-hosted SolarWinds Platform.

Automate SCM profile import or export

This topic explains how to automate Server Configuration Monitor (SCM) profile import or export using PowerShell script.

  • To create and manage SCM profiles programmatically, use create/update/delete operations on Orion.SCM.Profiles and Orion.SCM.ProfileElements entities.

  • To automate the exporting or import of profiles, use ExportProfile or ImportProfile verbs on Orion.SCM.Profile entities.

  • To assign profiles to nodes or unassign profiles from nodes, use AssignToNode and UnassignFromNode verbs on Orion.SCM.Profiles entities.

See the following script for an example of how to automate operations in SCM:

# This sample script demonstrates the use of verbs and CRUD operations provided for manipulating 
# with profiles and elements. The verbs are defined by "Orion.SCM.Profiles" entity type.
#
# The script progresses in several steps, it:
# 1. Creating new profile
# 2. Add several elements
# 3. Export profile
# 4. Delete element from profile
# 5. Assign profile to node to start monitoring
# 6. Unassign profile from node
# 7. Delete profile
# 8. Import profile
# 9. Delete imported profile

# Please update the hostname and credential setup to match your configuration.
if (! (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {
Add-PSSnapin "SwisSnapin"
}

# Connect to SWIS
Write-Host "Enter Orion host name or IP address:"
$hostname = Read-Host
Write-Host "Enter Orion username:"
$username = Read-Host
Write-Host "Enter Orion password:"
$password = Read-Host -AsSecureString
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$swis = Connect-Swis -host $hostname -cred $cred


#
# CREATE PROFILE
#
# Create empty profile and add few elements.
#

$profileProperties = @{
    Name = "MyNewProfile";
    Description = "This is description of my new profile";
}
$profileUri = New-SwisObject $swis -EntityType "Orion.SCM.Profiles" -Properties $profileProperties
$profile = Get-SwisObject $swis -Uri $profileUri
$profileId = $profile.ProfileID


Write-Host "New profile with ID = $profileId was created."

#
# ADD ELEMENT TO PROFILE
#
# Create new File and Registy element and assign it to created profile.
#

$elementProperties = @{
    ProfileID = $profileId;
    Type = "File";
    Description = "Monitoring XML files in Windows Logs folder.";
    Settings = @{
       Path = "%windir%\Logs\**\*xml";
       CollectContent = $true;
    }
}
$fileElementUri = New-SwisObject $swis -EntityType "Orion.SCM.ProfileElements" -Properties $elementProperties

$elementProperties = @{
    ProfileID = $profileId;
    Type = "Registry";
    Description = "Monitoring of Windows Update registry.";
    Settings = @{
       Path = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate";
       CollectContent = $true;
    }
}
$registryElementUri = New-SwisObject $swis -EntityType "Orion.SCM.ProfileElements" -Properties $elementProperties

#
# EXPORT PROFILE
#
# Export profile and save it to file
#

$exportedProfilePath = "c:\temp\exported.scm-profile"
(Invoke-SwisVerb $swis "Orion.SCM.Profiles" "ExportProfile" @($profileId)).InnerText | Out-File -FilePath $exportedProfilePath
Write-Host "Profile was exported to $exportedProfilePath"

#

 

# This sample script demonstrates the use of verbs and CRUD operations provided for manipulating
# with profiles and elements. The verbs are defined by "Orion.SCM.Profiles" entity type.
#
# The script progresses in several steps, it:
# 1. Creating new profile
# 2. Add several elements
# 3. Export profile
# 4. Delete element from profile
# 5. Assign profile to node to start monitoring
# 6. Unassign profile from node
# 7. Delete profile
# 8. Import profile
# 9. Delete imported profile
 
# Please update the hostname and credential setup to match your configuration.
if (! (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {
    Add-PSSnapin "SwisSnapin"
}
 
# Connect to SWIS
Write-Host "Enter Orion host name or IP address:"
$hostname = Read-Host
Write-Host "Enter Orion username:"
$username = Read-Host
Write-Host "Enter Orion password:"
$password = Read-Host -AsSecureString
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$swis = Connect-Swis -host $hostname -cred $cred
 
#
# CREATE PROFILE
#
# Create empty profile and add few elements.
#
 
$profileProperties = @{
    Name = "MyNewProfile";
    Description = "This is description of my new profile";
}
$profileUri = New-SwisObject $swis -EntityType "Orion.SCM.Profiles" -Properties $profileProperties
$profile = Get-SwisObject $swis -Uri $profileUri
$profileId = $profile.ProfileID
 
Write-Host "New profile with ID = $profileId was created."
 
#
# ADD ELEMENT TO PROFILE
#
# Create new File and Registy element and assign it to created profile.
#
 
$elementProperties = @{
    ProfileID = $profileId;
    Type = "File";
    Description = "Monitoring XML files in Windows Logs folder.";
    Settings = @{
        Path = "%windir%\Logs\**\*xml";
        CollectContent = $true;
    }
}
$fileElementUri = New-SwisObject $swis -EntityType "Orion.SCM.ProfileElements" -Properties $elementProperties
 
$elementProperties = @{
    ProfileID = $profileId;
    Type = "Registry";
    Description = "Monitoring of Windows Update registry.";
    Settings = @{
        Path = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate";
        CollectContent = $true;
    }
}
$registryElementUri = New-SwisObject $swis -EntityType "Orion.SCM.ProfileElements" -Properties $elementProperties
 
#
# EXPORT PROFILE
#
# Export profile and save it to file
#
 
$exportedProfilePath = "c:\temp\exported.scm-profile"
(Invoke-SwisVerb $swis "Orion.SCM.Profiles" "ExportProfile" @($profileId)).InnerText | Out-File -FilePath $exportedProfilePath
Write-Host "Profile was exported to $exportedProfilePath"
 
#
# ASSIGN PROFILE TO NODE
#
# Select node ID and assign created profile to it.
#
 
# Select the node
$ip = '10.140.127.223'
$nodeId = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE IP_Address=@ip" @{ip=$ip}
if (!$nodeId) {
  Write-Host "Can't find node with IP '$ip'."
  exit 1
}
 
Write-Host "Assigning new profile to node ID = $nodeId."
 
Invoke-SwisVerb $swis "Orion.SCM.Profiles" "AssignToNode" @(
    # Profile ID
    $profileId,
    # Node ID
    $nodeId
  )
 
Write-Host "Profile is assigned to node and it will start monitoring entities soon. Press ENTER to continue..."
Read-Host
 
#
# ADD NEW ELEMENT TO PROFILE
#
# Add new element to created profile and call PollNow to immediately apply changes.
#
 
Write-Host "Adding new PowerShell element to profile."
 
$elementProperties = @{
    ProfileID = $profileID;
    Type = "PowerShell";
    DisplayAlias = "Windows Services";
    Description = "Monitoring of services with their start type.";
    Settings = @{
        Path = "Get-Service | Format-Table -Property ServiceName, DisplayName, StartType";
        PollingFrequency = "0:10:00";
        PollingTimeout = "0:01:00";
    }
}
$powerShellElementUri = New-SwisObject $swis -EntityType "Orion.SCM.ProfileElements" -Properties $elementProperties
 
$nodeIds = ([xml]"<ArrayOfint xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/2003/10/Serialization/Arrays'><int>$nodeId</int></ArrayOfint>").DocumentElement
Invoke-SwisVerb $swis "Orion.SCM.ServerConfiguration" "PollNow" @(
    # Node ID list
    $nodeIds
  )  | Out-Null
 
Write-Host "Profile updated, configuration sent to node and it will start monitoring new PowerShell script soon. Press ENTER to clean up..."
Read-Host
 
#
# UNASSIGN PROFILE FROM NODE
#
# Unassign new profile from node and delete all historical data.
#
 
Invoke-SwisVerb $swis "Orion.SCM.Profiles" "UnassignFromNode" @(
    # Profile ID
    $profileId,
    # Node ID
    $nodeId,
    # Keep history data
    $false
  )
 
Write-Host "Profile was unassigned from node ID = $nodeId."
 
#
# DELETE ELEMENT
#
# Delete element from profile.
#
 
Remove-SwisObject $swis -Uri $fileElementUri
Write-Host "File element was removed from new profiles."
 
#
# DELETE PROFILE
#
# Delete profile.
#
 
Remove-SwisObject $swis -Uri $profileUri
Write-Host "New profile was removed from database. Press ENTER to continue..."
Read-Host
 
#
# IMPORT PROFILE
#
# Import profile
#
 
$fileContent = Get-Content -Path $exportedProfilePath
$importedProfileId = (Invoke-SwisVerb $swis "Orion.SCM.Profiles" "ImportProfile" @($fileContent)).InnerText
Write-Host "Profile was imported with ID = $importedProfileId. Press ENTER to continue..."
Read-Host
 
$importedProfileUri = Get-SwisData $swis "SELECT Uri FROM Orion.SCM.Profiles WHERE ProfileID=@id" @{id=$importedProfileId}
Remove-SwisObject $swis -Uri $importedProfileUri
Write-Host "Imported profile was removed from database."
 
Remove-Item -Path $exportedProfilePath
Write-Host "Deleted file $exportedProfilePath