Skip to content

Commit

Permalink
Update Install-ManualDCAgents.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
x-limitless-x authored Jun 25, 2021
1 parent a0627e9 commit 07331bf
Showing 1 changed file with 55 additions and 28 deletions.
83 changes: 55 additions & 28 deletions Powershell/Install-ManualDCAgents.ps1
Original file line number Diff line number Diff line change
@@ -1,36 +1,63 @@
cls

<#
$Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$AllComputers = ($Forest.Sites | % { $_.Servers } | SORT Domain,name).Name
#>
Write-Host 'Updating Agents!'
$AllComputers = 'DomainController1.contoso.com'
function Time-Stamp
{
$TimeStamp = Get-Date -Format "MM/dd/yyy hh:mm:ss tt"
Write-Host $TimeStamp -NoNewLine -ForegroundColor DarkGray
}
Write-Host @"
====================
Updating SCOM Agents
====================
"@
$AllComputers = 'DC01.contoso.com'
ForEach ($Computer in $AllComputers)
{
Write-Host "*** $Computer ***"
##$Computer
Copy-Item "C:\Temp\MOMAgent.msi" "\\$Computer\C`$\temp\" -Force -ErrorAction Stop
Copy-Item "C:\Temp\KB4580254-amd64-Agent.msp" "\\$Computer\C`$\temp\" -Force -ErrorAction Stop
Invoke-Command -ComputerName $Computer -ScriptBlock {
$path_to_install = 'C:\Temp\MOMAgent.msi'
Write-Host "Uninstalling Agent"
start-process -FilePath "msiexec.exe" -ArgumentList "/x $path_to_install /qn /l*v C:\Temp\AgentUninstall.log"
$args = "USE_SETTINGS_FROM_AD=0 USE_MANUALLY_SPECIFIED_SETTINGS=1 MANAGEMENT_GROUP=ManagementGroup1 MANAGEMENT_SERVER_DNS=MS1.contoso.com MANAGEMENT_SERVER_AD_NAME=MS1.contoso.com SECURE_PORT=5723 ACTIONS_USE_COMPUTER_ACCOUNT=1 AcceptEndUserLicenseAgreement=1"
$args = "/i " + $path_to_install + " /quiet /qn /l*v C:\Temp\SCOMAgentInstall.log " + $args
# Install Ops Manager Agent
Write-Host 'Installing MOMAgent.msi'
start-process -FilePath "msiexec.exe" -ArgumentList $args
sleep 10
Write-Host 'Starting HSLockdown'
start-process -FilePath "C:\Program Files\Microsoft Monitoring Agent\Agent\HSLockdown.exe" -ArgumentList "/A `"NT Authority\System`""
sleep 10
Write-Host 'Restarting Microsoft Monitoring Agent.'
Restart-Service HealthService -Force
$path_to_install = 'C:\Temp\KB4580254-amd64-Agent.msp'
$args = "AcceptEndUserLicenseAgreement=1"
$args = "/i " + $path_to_install + " /quiet /qn /l*v C:\Temp\SCOMUpgradeInstall.log " + $args
# Install Ops Manager Agent
Write-Host 'Installing Agent Update Rollup'
start-process -FilePath "msiexec.exe" -ArgumentList $args
}
Time-Stamp
Write-Host " $Computer" -ForegroundColor DarkCyan
##$Computer
Copy-Item "C:\Temp\MOMAgent.msi" "\\$Computer\C`$\temp\" -Force -ErrorAction Stop
Copy-Item "C:\Temp\KB4580254-amd64-Agent.msp" "\\$Computer\C`$\temp\" -Force -ErrorAction Stop
Invoke-Command -ComputerName $Computer -ScriptBlock {
Stop-process -Name msiexec -Force
function Time-Stamp
{
$TimeStamp = Get-Date -Format "MM/dd/yyy hh:mm:ss tt"
Write-Host $TimeStamp -NoNewLine -ForegroundColor DarkGray
}
$path_to_install = 'C:\Temp\MOMAgent.msi'
# Uninstall Agent
Time-Stamp
Write-Host "`t - Uninstalling Agent" -ForegroundColor Cyan
start-process -FilePath "msiexec.exe" -ArgumentList "/x $path_to_install /qn /l*v C:\Temp\AgentUninstall.log" -Wait -ErrorAction Stop
Sleep 1
$args = "USE_SETTINGS_FROM_AD=0 USE_MANUALLY_SPECIFIED_SETTINGS=1 MANAGEMENT_GROUP=ManagementGroup1 MANAGEMENT_SERVER_DNS=MS1.contoso.com MANAGEMENT_SERVER_AD_NAME=MS1.contoso.com SECURE_PORT=5723 ACTIONS_USE_COMPUTER_ACCOUNT=1 AcceptEndUserLicenseAgreement=1"
$args = "/i " + $path_to_install + " /quiet /qn /l*v C:\Temp\SCOMAgentInstall.log " + $args
# Install Ops Manager Agent
Time-Stamp
Write-Host "`t - Installing MOMAgent.msi" -ForegroundColor Cyan -NoNewLine
start-process -FilePath "msiexec.exe" -ArgumentList $args -Wait -ErrorAction Stop

sleep 1
Time-Stamp
Write-Host "`t - Adding 'NT Authority\System' to HSLockdown" -ForegroundColor Cyan
start-process -FilePath "C:\Program Files\Microsoft Monitoring Agent\Agent\HSLockdown.exe" -ArgumentList "/A `"NT Authority\System`"" -Wait -ErrorAction Stop
sleep 1
Time-Stamp
Write-Host "`t - Restarting Microsoft Monitoring Agent" -ForegroundColor Cyan
Restart-Service HealthService -Force
# Install Ops Manager Agent Update Rollup
$path_to_install = 'C:\Temp\KB4580254-amd64-Agent.msp'
$msiArgs = "/update `"$path_to_install`" /quiet"
Time-Stamp
Write-Host "`t - Installing Agent Update Rollup" -ForegroundColor Cyan -NoNewLine
Start-Process -FilePath msiexec -ArgumentList $msiArgs -Wait -ErrorAction Stop
Time-Stamp
Write-Host "`t -- Complete!" -ForegroundColor Green
}

}

0 comments on commit 07331bf

Please sign in to comment.