Scripts/GetOpsMgrSetupRegKeyInfo.ps1

<#
.Synopsis
   Returns values from HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup
.DESCRIPTION
   Returns values from HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup
.OUTPUTS
   A JSON string with values from registry key
#>

[CmdletBinding()]
[OutputType([string])]
Param
(
)
# Define the class so that it can easily be converted to JSON
Add-Type -TypeDefinition @"
public class OpsMgrSetupRegKey{
    public string CurrentVersion;
    public string DatabaseName;
    public string DatabaseServerName;
    public string DatabaseVersion;
    public string DataWarehouseDBName;
    public string DataWarehouseDBServerName;
    public string InstallDirectory;
    public string InstalledOn;
    public string ManagementServerPort;
    public string Product;
    public string ServerVersion;
    public string UIVersion;
}
"@


# this is the path we want to retrieve the values from
$opsMgrSetupRegKeyPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup'

# get the values
$opsMgrSetupRegKey = Get-ItemProperty -Path $opsMgrSetupRegKeyPath

# construct a new object
$opsMgr = New-Object OpsMgrSetupRegKey

#set the object values from the registry key
$opsMgr.CurrentVersion = $opsMgrSetupRegKey.CurrentVersion
$opsMgr.DatabaseName = $opsMgrSetupRegKey.DatabaseName
$opsMgr.DatabaseServerName = $opsMgrSetupRegKey.DatabaseServerName
$opsMgr.DatabaseVersion = $opsMgrSetupRegKey.DatabaseVersion
$opsMgr.DataWarehouseDBName = $opsMgrSetupRegKey.DataWarehouseDBName
$opsMgr.DataWarehouseDBServerName = $opsMgrSetupRegKey.DataWarehouseDBServerName
$opsMgr.InstallDirectory = $opsMgrSetupRegKey.InstallDirectory
$opsMgr.InstalledOn = $opsMgrSetupRegKey.InstalledOn
$opsMgr.ManagementServerPort = $opsMgrSetupRegKey.ManagementServerPort
$opsMgr.Product = $opsMgrSetupRegKey.Product
$opsMgr.ServerVersion = $opsMgrSetupRegKey.ServerVersion
$opsMgr.UIVersion = $opsMgrSetupRegKey.UIVersion

# convert the OpsMgrSetupRegKey to JSON
$json = ConvertTo-Json $opsMgr

return $json