User Tools

Site Tools


correr_paquete_msi_en_todas_las_computadoras_del_dominio

Un ejemplo de cómo correr el package msi para laps x64

# This script gets all AD computers and stores their names in the $PCName variable
$PCName = Get-ADComputer -Filter * -Properties * | Select-Object -ExpandProperty Name
 
# This command runs the LAPS installer on all the computers in the $PCName variable
Invoke-Command -ComputerName $PCName -ScriptBlock { 
    msiexec /q /i \\SERVERNAME\SHARENAME\LAPS.x64.msi 
}

Ejecutar .msi en máquinas Windows Server que estén corriendo un servicio en particular

# Import the Active Directory module
Import-Module ActiveDirectory
 
# Define the filter for the operating system
$osFilter = "*Windows Server*"
 
# Query Active Directory for computers with the specified operating system
$computers = Get-ADComputer -Filter "OperatingSystem -like '$osFilter'" -Property Name, OperatingSystem
 
# Prompt for credentials once
$credential = Get-Credential
 
# Initialize an array to store the results
$results = @()
 
# Loop through each computer and check if it's online
foreach ($computer in $computers) {
    $server = $computer.Name
    $osVersion = $computer.OperatingSystem
    $pingResult = Test-NetConnection -ComputerName $server -InformationLevel Quiet
 
    if ($pingResult) {
        $onlineStatus = "yes"
        # Check if the HealthService or Microsoft Monitoring Agent service is running
        $service = Get-Service -ComputerName $server -Name "HealthService", "Microsoft Monitoring Agent" -ErrorAction SilentlyContinue
 
        if ($service) {
            $serviceStatus = "no"
            foreach ($s in $service) {
                if ($s.Status -eq 'Running') {
                    $serviceStatus = "running"
                    # Run the uninstallation command
                    Invoke-Command -ComputerName $server -ScriptBlock {
                        Start-Process msiexec.exe -ArgumentList '/x C:\Temp\MOMAgent.msi /quiet' -Wait -NoNewWindow
                    } -Credential $credential
                    break
                }
            }
        } else {
            $serviceStatus = "not installed"
        }
    } else {
        $onlineStatus = "no"
        $serviceStatus = "n/a"
    }
 
    # Add the result to the array
    $results += [PSCustomObject]@{
        ServerName = $server
        OperatingSystem = $osVersion
        Online = $onlineStatus
        MOMAgentService = $serviceStatus
    }
}
 
# Export the results to a CSV file
$results | Export-Csv -Path "C:/temp/MOMAgentHosts.csv" -NoTypeInformation
 
Write-Output "Results have been exported to C:/temp/MOMAgentHosts.csv"
correr_paquete_msi_en_todas_las_computadoras_del_dominio.txt · Last modified: 2024/10/18 18:02 by oso