Microsoft 365 Verify Prerequisites Task

Microsoft.SystemCenter.M365.Tasks.VerifyPrerequisitesTask (Task)

Verify presence of prerequisites for the Microsoft 365 management pack watcher node.

Element properties:

TargetMicrosoft.SystemCenter.HealthService
AccessibilityPublic
CategoryCustom
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
ExecuteScript WriteAction Microsoft.SystemCenter.M365.PowerShellWriteAction.Prerequisites Microsoft.SystemCenter.PrivilegedMonitoringAccount

Source Code:

<Task ID="Microsoft.SystemCenter.M365.Tasks.VerifyPrerequisitesTask" Accessibility="Public" Enabled="true" Target="SC!Microsoft.SystemCenter.HealthService" Timeout="300" Remotable="true">
<Category>Custom</Category>
<WriteAction ID="ExecuteScript" TypeID="Microsoft.SystemCenter.M365.PowerShellWriteAction.Prerequisites" RunAs="SC!Microsoft.SystemCenter.PrivilegedMonitoringAccount">
<ScriptName>VerifyPrerequisites.ps1</ScriptName>
<ScriptBody><Script>Param( [parameter(Mandatory=$false)] [string] $SkypeForBusinessNetworkAssessmentToolDesired = 'true' )

$api = new-object -comObject 'MOM.ScriptAPI'
$scriptName = "VerifyPrerequisites"
$eventId = 980
$api.LogScriptEvent($scriptName,$eventId,0,"Running script '$scriptName' (as '$(whoami)').")

#=========================================================================================
# Functions

function ConvertToBool([string] $value)
{
if (($value -eq $null) -or ($value -eq ''))
{
return $false
}
if ($value -like 'true')
{
return $true
}
return $false
}

function Is-CurrentUserMemberOfLocalAdministratorsGroup
{
$identityReferences = [Security.Principal.WindowsIdentity]::GetCurrent().Groups
foreach ($identityReference in $identityReferences)
{
if ($identityReference.Value -eq "S-1-5-32-544") #BuiltinAdministratorsSid
{
return $true
}
}
return $false
}

function Verify-PowerShell5
{
if ($psVersionTable.PSVersion.Major -ge 5)
{
return 'AlreadyInstalled'
}
return 'NotInstalled'
}

function Verify-DotNetVersion
{
$step = 'Verifying .Net version'
$item = Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -ErrorAction ignore
if (($item -ne $null) -and ($item.Release -ge 461808)) #4.7.2
{
return 'AlreadyInstalled'
}
return 'NotInstalled'
}

function Verify-NetworkAssessmentTool
{
$installed = Test-Path "${env:ProgramFiles(x86)}\Microsoft Teams Network Assessment Tool\NetworkAssessmentTool.exe"
if ($installed)
{
return 'AlreadyInstalled'
}
return 'NotInstalled'
}

#=========================================================================================
# Main

$output = ''
if (!(Is-CurrentUserMemberOfLocalAdministratorsGroup))
{
$output = "Warning: Script run as user ('$(whoami)') who is not a member of the local Administrators group.
Install task must be run as an account (i.e. 'SYSTEM') that is a member of the local Administrators group.
"
}

$NetworkAssessmentToolDesired = ConvertToBool $SkypeForBusinessNetworkAssessmentToolDesired

$output = $output + "Prerequisite=PowerShell Version 5:$(Verify-PowerShell5);`r`n"
$output = $output + "Prerequisite=.Net Version 4.7.2 or greater:$(Verify-DotNetVersion);`r`n"

if ($NetworkAssessmentToolDesired)
{
$output = $output + "Prerequisite=Microsoft Teams Network Assessment Tool:$(Verify-NetworkAssessmentTool);`r`n"
}
$api.LogScriptEvent($scriptName,$eventId,0,"Script finished. Returning: '$output'.")
$output
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>false</StrictErrorHandling>
<SkypeForBusinessNetworkAssessmentToolDesired>True</SkypeForBusinessNetworkAssessmentToolDesired>
</WriteAction>
</Task>