#Check and see if OS is Nano server
$isNano = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels"
$isNano = $isNano.NanoServer
if($isNano -ne $null)
{
$isNano = $true
}
else
{
$isNano = $false
}
#Get the Updated UR level agent version from a file
If ($IsAgent)
{
$AgentPath = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup" | select InstallDirectory -ErrorAction stop
$AgentPath = $AgentPath.InstallDirectory
If ($isNano)
{
#IsNano was True. Getting version from OMVersion.dll file
try
{
$AgentVersionFile = $AgentPath + "Tools\TMF\OMVersion.Dll"
$ToolsFile = Get-ItemProperty $AgentVersionFile | select VersionInfo -ErrorAction stop
$ToolsFileVersion = $ToolsFile.VersionInfo.FileVersion
$Version = $ToolsFileVersion
}
catch
{
$oAPI.LogScriptEvent($ScriptName, 11, 1, "The Nano Agent file version check had an error, error: ", $error.Description)
#Getting version from agent Registry due to file error
$Version = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup" | select AgentVersion -ErrorAction stop
$Version = $Version.AgentVersion
}
}
Else
{
#IsNano was False. Treating as normal agent
try
{
$AgentVersionFile = $AgentPath + "Tools\TMF\OMAgentTraceTMFVer.Dll"
$ToolsFile = Get-ItemProperty $AgentVersionFile | select VersionInfo -ErrorAction stop
$ToolsFileVersion = $ToolsFile.VersionInfo.FileVersion
$Version = $ToolsFileVersion
}
catch
{
$oAPI.LogScriptEvent($ScriptName, 11, 1, "The Agent file version check had an error, error: ", $error.Description)
#Getting version from agent Registry due to file error
$Version = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup" | select AgentVersion -ErrorAction stop
$Version = $Version.AgentVersion
}
}
}
Else
{
#IsAgent was false. Getting version from Registry for management server or gateway
$Version = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup" | select CurrentVersion -ErrorAction stop
$Version = $Version.CurrentVersion
}
# Get the action account this script is running under. We will assume that is the default agent action account
try
{
$user = ""
$domain = ""
if($isNano)
{
$user = $env:username
$domain = $env:userdnsdomain
}
else
{
$oNetwork = new-object -comobject "WScript.Network"
$user = $oNetwork.UserName
$domain = $oNetwork.UserDomain
}
If(($user.Length -eq 0) -or ($user -eq "SYSTEM"))
{
$ActionAccount = $user
}
Else
{
$ActionAccount = $domain + "\" + $user
}
}
catch
{
$oAPI.LogScriptEvent($ScriptName, 11, 1, "Failed to retrieve the User name and domain for the action account, error: ", $error.Description)
Exit -1;
}