Blog Arksoft
  • Arksoft Bilisim
  • Scripts
    • SCCM (ConfigMgr)
    • Hyper-V
    • WSUS
    • Exchange Scripts
      • Exchange Virtual Directory Config
      • Virtual Directory Script
      • LogPath Config
      • Queue Database Move
      • Receive Connector Copy
  • HAZİRAN 2025
    • Windows 11'de Quick Machine Recovery: PC Hatalarına Karşı Yeni Nesil Dayanıklılık
    • Exchange Server’da Kota ve Limit Ayarları: Temel Bilgiler ve Kullanım Alanları
  • MAYIS 2025
    • Microsoft’un Mayıs 2025 Güncellemeleri: Sistem Yöneticileri İçin Kapsamlı Özet
  • NİSAN 2025
    • Exchange Server 2019 CU15 Apr25HU
    • Nisan 2025:Microsoft Güvenlik Güncellemeleri
    • Power BI Gateway ile On-Prem Verilerin Gücünü Keşfedin!
    • IT Personelleri Neden Adli Bilişim Farkındalık Eğitimi Almalıdır?
    • ''SCCM 2503'' Sürüm Yükseltme Rehberi
  • Mart 2025
    • SCCM Üzerinden Kritere Göre Uygulama ve Deployment’ları Otomatik Silmek
    • Mart 2025: Microsoft Güvenlik Güncellemeleri
  • ŞUBAT 2025
    • SPN Nedir, Kerberos Nasıl Çalışır ve Duplicate SPN Neden Sorun Yaratır?
    • Şubat 2025: Microsoft'un Güvenlik Güncellemeleriyle Sistemlerinizi Güçlendirin!
    • Exchange Server CU15 Güncellemesi
    • log_reuse_wait_desc Nedir ve Ne Anlatır?
  • OCAK 2025
    • Azure SQL Nedir? Temel Bilgiler ve Avantajlar
    • Live Migration için Ağ Kartı Seçerken Dikkat Edilmesi Gerekenler
    • Protected Attribute Nedir? Nasıl Oluşturulur?
    • Ocak 2025 Microsoft Güvenlik Güncellemeleri: Sistemlerinizi Güvende Tutun!
    • CLIUSR Hesabı Neden Önemlidir? CLIUSR sertifikası nedir, neden süresi doldu uyarısı alıyorum?
  • ARALIK 2024
    • TLS 1.2 Öncesi Protokollerin Güvenlik Açıkları ve TLS 1.2/1.3 Önemi
  • Kasım 2023
    • Microsoft Exchange Server Kasım Ayı Güvenlik Güncellemesi
  • Temmuz 2023
    • Microsoft Office Zero-Day Zafiyeti CVE-2023-36884
  • Mayis 2023
    • Hashing ve Salting Kavramları Nedir? Azure AD Parola Güvenliği Nasıl Sağlanır?
  • Nisan 2023
    • DDOS Saldırıları Nedir ve Korunma Yolları Nelerdir?
    • Fidye Yazılımları Nedir ve Korunma Yöntemleri Nelerdir?
    • Ransomwares And Defence Strategies
    • PowerShell Modülleri: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Fonksiyonları: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Cmdlet'ler: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Değişkenleri: Temel Kavramlar ve Kullanım Örnekleri
    • PowerShell Nedir?
    • Oltalama E-Postalarından Korunma
    • CVE-2023-2033
    • Cloud Computing and Its Advantages
    • Bulut Bilişim Nedir ve Bulut Bilişimin Avantajları Nelerdir?
    • Bilgi ve İletişim Güvenliği Rehberi Nedir ve Rehbere Uyumlu Olmak Neden Önemlidir?
  • Mart 2023
    • Sık Kullanılan Portlar ve Üzerinde Çalışan Protokoller
    • Siber Güvenlik ve İnternet Dünyasında Güvende Kalmanın Yolları
    • Outlook Kullanıcılarına Uyarı: CVE-2023-23397 Güvenlik Açığına Karşı Önlem Alın
  • Şubat 2023
    • Üçüncü Parti Uygulamaların Güncellenmesinin Önemi
  • Aralık 2022
    • Siber Tehdit
    • FRS to DFSR Migration
  • Kasım 2022
    • Domain Controller 2022 Kasım Ayı Bug'ı
  • Mart 2022
    • OWA ve ECP erişim sorunu: Microsoft Exchange Server Auth Certificate is expired
    • MIM 2016 SSPR Türkçe Karakter Problemi
  • Haziran 2021
    • KMS (Key Management Service)
  • Ağustos 2020
    • Microsoft Teams Konuk (Guest) Erişimi ve Dış (External) Erişim- Sizin için hangisi uygun?1
    • SCCM 2006 Güncellemesi
    • Skype For Business 2019 Kurulumu- Hata Kodu 1603 (Server.msi(Feature_Server, Feature_HealthyAgent))
    • Skype for Business 2019 “Centralized Logging” Servisinin Başlatılamaması Problemi ve Çözümü
  • Temmuz 2020
    • Clean Inactive Agents from Operations Manager
  • Haziran 2020
    • Microsoft Teams Katılımcı Raporu İndirme
    • Microsoft Teams Toplantı ve Grup Sohbet Sınırı 300'e çıkarıldı
  • Mayıs 2020
    • MIM 2016 Service and Portal Kurulumundaki Bug
    • Telegram ve Powershell ile Sistem İzleme-Part 1
  • Ekim 2019
    • Windows Server 2019 Active Directory Domain Services Kurulumu
  • Nisan 2019
    • Huawei FusionCompute Kurulumu
  • Mart 2019
    • Password Reveal Düğmesi
  • Ocak 2019
    • ReportServer Veri Tabanı içerisinden RDL Dosyalarının Çıkartılması
  • Temmuz 2018
    • Active Directory Certificate Services - SHA1’ den SHA2’ ye Yükseltme
    • Local Administrator Password Solution
Powered by GitBook
On this page
  1. Temmuz 2020

Clean Inactive Agents from Operations Manager

Direnc Onen

PreviousSkype for Business 2019 “Centralized Logging” Servisinin Başlatılamaması Problemi ve ÇözümüNextMicrosoft Teams Katılımcı Raporu İndirme

Last updated 2 years ago

Clean Inactive Agents from Operations Manager – Direnc Onen

Many times, we would like to clean inactive agents from Operations Manager automatically. But Operations Manager has no option to clean or display inactive agents on console. I will explain how can you analyze Operations Manager agent healthy and accessible. You can use this script in Orchestrator to clean inactive agents automatically.

We will write custom PowerShell script to analyze inactive agents. I will explain every script part.

High steps;

  1. Prerequisites

  2. Writing Custom PowerShell script

Detailed steps;

  1. Prerequisites,

    • In this script, we will test connectivity of an agent. If we couldn’t connect to agent, then we will test DNS Name resolution of this agent. So, we need DNS aging and scavenging options have to be active. When this option active, DNS records (dynamically registered records) removed from DNS database automatically. By default, aging and scavenging of resource records is disabled. These options must be enabled, both at the DNS Server and on the zone. You can read details about aging and scavenging . If you enable these options, removed servers resource records deleted automatically by DNS Server.

    • If you have any agents that can’t be resolve hostname – IP address information, you may add hostname – IP address information on hosts file located in management server. Because our script test DNS name resolution and connectivity with ping command. If you don’t add address information to DNS Server or hosts file, you can delete active agents that running on workgroup or another domain.

  2. Writing Custom PowerShell script,

    • First we need to add some assemblies to our script to connect and manage operations manager.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.EnterpriseManagement.OperationsManager.Common”) [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.EnterpriseManagement.OperationsManager”)

  • With the following code block we will connect to the one of the management server with current credentials.

$MGConnSetting = New-Object Microsoft.EnterpriseManagement.ManagementGroupConnectionSettings(“scomserver.fqdn.name”) $MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup($MGConnSetting) $admin = $MG.Administration

  • At this part, we collect all of agents managed by Operations Manager.

$agentManagedComputerType = [Microsoft.EnterpriseManagement.Administration.AgentManagedComputer]; $genericListType = [System.Collections.Generic.List“1] $genericList = $genericListType.MakeGenericType($agentManagedComputerType) $agents = Get-SCOMAgent $Inacti = new-object $genericList.FullName $Inacti.Clear() $Unreach = new-object $genericList.FullName $Unreach.Clear()

  • Now, time to test computer-agent connectivity. We will use test-connection PowerShell cmdlet to test computer connectivity. We add every agent object to the “$Inacti” array that can’t be connect. At the end of foreach cycle, we will have a list that cannot connect to the agents.

foreach ($agent in $agents) { if (Test-Connection -ComputerName $agent.DisplayName -Quiet -Count 1) { ## Server is Accessible } else { $Inacti.Add($agent); } }

In this ForEach loop we test name resolution of every inactive agents. If no ip address return of server then we add this agent $Unreach array.

foreach ($InActiveAgent in $Inacti) { $ip = (Resolve-DnsName -Name $InActiveAgent.DisplayName -ErrorAction SilentlyContinue).IPAddress if ($ip.Length -le 0) { $Unreach.Add($InActiveAgent) } }

  • If $Unreach list has more than 0 agent information, these agent removed with the following part of script.

if ($Unreach.Count -gt 0) { $genericReadOnlyCollectionType = [System.Collections.ObjectModel.ReadOnlyCollection“1] $genericReadOnlyCollection = $genericReadOnlyCollectionType.MakeGenericType($agentManagedComputerType) $agentReadOnlyCollection = new-object $genericReadOnlyCollection.FullName @(,$Unreach); $admin.DeleteAgentManagedComputers($Unreach) }

You should be careful when you running this script. If you have any problem with name resolution on your network, you can delete active agents accidentally.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.EnterpriseManagement.OperationsManager.Common”) [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.EnterpriseManagement.OperationsManager”) $MGConnSetting = New-Object Microsoft.EnterpriseManagement.ManagementGroupConnectionSettings(“scomserver.fqdn.name”) $MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup($MGConnSetting) $admin = $MG.Administration$agentManagedComputerType = [Microsoft.EnterpriseManagement.Administration.AgentManagedComputer]; $genericListType = [System.Collections.Generic.List“1] $genericList = $genericListType.MakeGenericType($agentManagedComputerType) $agents = Get-SCOMAgent $Inacti = new-object $genericList.FullName $Inacti.Clear() $Unreach = new-object $genericList.FullName $Unreach.Clear() foreach ($agent in $agents) { if (Test-Connection -ComputerName $agent.DisplayName -Quiet -Count 1) { ## Server is Accessible } else { $Inacti.Add($agent); } } foreach ($InActiveAgent in $Inacti) { $ip = (Resolve-DnsName -Name $InActiveAgent.DisplayName -DnsOnly -ErrorAction SilentlyContinue).IPAddress if ($ip.Length -le 0) { $Unreach.Add($InActiveAgent) } } if ($Unreach.Count -gt 0) { $genericReadOnlyCollectionType = [System.Collections.ObjectModel.ReadOnlyCollection“1] $genericReadOnlyCollection = $genericReadOnlyCollectionType.MakeGenericType($agentManagedComputerType) $agentReadOnlyCollection = new-object $genericReadOnlyCollection.FullName @(,$Unreach); $admin.DeleteAgentManagedComputers($Unreach) }

Complete script:

You can download script file .

here
here