Install-MMA-on-Nano-Server.ps1


<#PSScriptInfo
 
.VERSION 1.0.2
 
.GUID 5da7965b-b1bc-4e4b-80ff-9fd89192cc7f
 
.AUTHOR Gregory May
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS Nano MMA Microsoft Monitoring Agent
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 This script installs MMA on Nano Server without SCOM dependancies.
 The agent install file MMASetup-AMD64.exe must exist in the current path. Download from https://go.microsoft.com/fwlink/?LinkId=828603 or your OMS workspace.
 This script has to be run with administrative privileges. The user account which is used to connect to the Nano Server must also have administrative rights on the Nano Server.
 
.SYNOPSIS
Remotely installs the Microsoft Monitoring Agent on to Nano Servers.
 
.EXAMPLE
Install-MMA-on-Nano-Server.ps1 MyNanoServerName 1234567 1234567
 
#>
 


param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] [string]$NanoServer, 
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] [string]$OPSINSIGHTS_WS_ID,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] [string]$OPSINSIGHTS_WS_KEY)

Write-Output "`nAdding $NanoServer to local WSMAN TrustedHosts client list"
Set-Item wsman:localhost\Client\TrustedHosts "$NanoServer" -Concatenate â€“Force
Write-Output "`nInitiating PSSession to $NanoServer"
$TargetSession = new-PSSession -ComputerName $NanoServer -Credential (Get-Credential)
Write-Output "Copying MMASetup-AMD64.exe file to $NanoServer C:\"
Copy-Item -Path ".\MMASetup-AMD64.exe" -Destination "C:\" -force -ToSession $TargetSession -Verbose
If ($?) {
    New-PSSession $TargetSession
    Write-Output "`nExecuting remote installation with: `n Workspace ID: $OPSINSIGHTS_WS_ID `n Workspace Key: $OPSINSIGHTS_WS_KEY"
    $installcmd = "C:\MMASetup-AMD64.exe"
    $installargs = "/Q:A /R:N /C:""setup.exe /qn ADD_OPINSIGHTS_WORKSPACE=1 OPINSIGHTS_WORKSPACE_ID=$OPSINSIGHTS_WS_ID OPINSIGHTS_WORKSPACE_KEY=$OPSINSIGHTS_WS_KEY AcceptEndUserLicenseAgreement=1"""
    Invoke-command -session $TargetSession -scriptblock {
        param($Rinstallcmd, $Rinstallargs)
        Write-Output "`n$Rinstallcmd $Rinstallargs"
        start-process $Rinstallcmd -ArgumentList $Rinstallargs -Wait
        Write-Output "`nWaiting 20 seconds for HealthService to bootstrap and start"
        Start-Sleep -s 20
        Get-Service healthservice
        Remove-Item C:\MMASetup-AMD64.exe -Force } -ArgumentList $installcmd, $installargs
}
Else {
    Write-Output "Unable to Copy File. Check Powershell version = WMF5 and MMASetup-AMD64.exe (https://go.microsoft.com/fwlink/?LinkId=828603) is in current path."
    Break
}