gesucht Script um Server aus der Datenbank löschen zu können.

Startseite – Aktivität Foren System Center Operations Manager Konfiguration & Architektur gesucht Script um Server aus der Datenbank löschen zu können.

This topic contains 1 reply, has 2 voices, and was last updated by  Thomas Valenta 7 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #347

    Dirk Decher
    Participant

    Hallo zusammen

    Ich habe das Problem, dass ich 3 Server unter Agent Health State finde, welche bei mir aber unter dem Device Managed nicht finden kann.
    Gibt es ein Script, mit dem ich diese 3 Server sauber aus der Datenbank löschen kann? So dass ich dann nochmals versuchen kann diese Server neu aufzunehmen?
    Dank euch. Gruss Dirk

    #468

    Thomas Valenta
    Participant

    Folgendes als PS1 Datei Speichern:

    function Get-SDKServerName
    {
     # Get SDK server name
     # Lifted from Microsoft.EnterpriseManagement.OperationsManager.CleintShell.Functions.ps1
     $UserRegKeyPath = “HKCU:softwareMicrosoftMicrosoft Operations Manager3.0User Settings”;
     $MachineRegKeyPath = “HKLM:softwareMicrosoftMicrosoft Operations Manager3.0Machine Settings”;
     $UserRegValueName = “SDKServiceMachine”;
     $MachineRegValueName = “DefaultSDKServiceMachine”;
     $regValue = $null;
     $server = $null;

     $regValue = Get-ItemProperty -path:$UserRegKeyPath -name:$UserRegValueName -ErrorAction:SilentlyContinue;

     if ($regValue -ne $null)
     {
         $server = $regValue.SDKServiceMachine;
     }

     if ($server -eq $null -or $server.Length -eq 0)
     {
         $regValue = Get-ItemProperty -path:$MachineRegKeyPath -name:$MachineRegValueName -ErrorAction:SilentlyContinue;
        
         if ($regValue -ne $null)
         {
             $server = $regValue.DefaultSDKServiceMachine;
         }
     }

     if ($server -eq $null)
     {
         $server = “localhost”
     }

     return $server
    }

    function Get-InstallDirectory
    {
     # Get Install directory
     $SetupRegKeyPath = “HKLM:softwareMicrosoftMicrosoft Operations Manager3.0Setup”;
     $InstallDirRegValueName = “InstallDirectory”;

     $InstallDir = “$env:SystemDriveProgram FilesSystem Center Operations Manager 3.0”;

     $regvalue = $null;
     $regValue = Get-ItemProperty -path:$SetupRegKeyPath -name:$InstallDirRegValueName -ErrorAction:SilentlyContinue;
     if ($regvalue -ne $null)
     {
         $InstallDir = $regValue.InstallDirectory;
     }

     return $InstallDir
    }

     

    function New-Collection ( [type] $type )
    {
     $typeAssemblyName = $type.AssemblyQualifiedName;
     $collection = new-object “System.Collections.ObjectModel.Collection“1$typeAssemblyName“;
     return ,($collection);
    }

    # Load SDK dlls
    $server = Get-SDKServerName
    $InstallDir = Get-InstallDirectory
    $sdkDir = “$InstallDirSDK Binaries”
    echo “Loading SDK”
    $dummy = [System.Reflection.Assembly]::LoadFrom(“$sdkDirMicrosoft.EnterpriseManagement.OperationsManager.Common.dll”)
    $dummy = [System.Reflection.Assembly]::LoadFrom(“$sdkDirMicrosoft.EnterpriseManagement.OperationsManager.dll”)

    # Connect to management group
    echo “Connecting to management group”
    $managementGroup = [Microsoft.EnterpriseManagement.ManagementGroup]::Connect($server)
    $admin = $managementGroup.GetAdministration()

    echo “Getting agent managed computers”
    $agentManagedComputers = $admin.GetAllAgentManagedComputers()

    # Get list of agents to delete
    foreach ($name in $args)
    {
        echo “Checking for $name”
        foreach ($agent in $agentManagedComputers)
        {
            if ($deleteCollection -eq $null)
            {
                $deleteCollection = new-collection $agent.GetType()
            }

           
            if (@($agent.PrincipalName -eq $name))
            {
         echo “Matched $name”
                $deleteCollection.Add($agent)
                break
            }
        }
    }

    if ($deleteCollection.Count -gt 0)
    {
        echo “Deleting agents”
        $admin.DeleteAgentManagedComputers($deleteCollection)
        if($?){ echo “Agents deleted” }
    }
    function Get-SDKServerName
    {
     # Get SDK server name
     # Lifted from Microsoft.EnterpriseManagement.OperationsManager.CleintShell.Functions.ps1
     $UserRegKeyPath = “HKCU:softwareMicrosoftMicrosoft Operations Manager3.0User Settings”;
     $MachineRegKeyPath = “HKLM:softwareMicrosoftMicrosoft Operations Manager3.0Machine Settings”;
     $UserRegValueName = “SDKServiceMachine”;
     $MachineRegValueName = “DefaultSDKServiceMachine”;
     $regValue = $null;
     $server = $null;

     $regValue = Get-ItemProperty -path:$UserRegKeyPath -name:$UserRegValueName -ErrorAction:SilentlyContinue;

     if ($regValue -ne $null)
     {
         $server = $regValue.SDKServiceMachine;
     }

     if ($server -eq $null -or $server.Length -eq 0)
     {
         $regValue = Get-ItemProperty -path:$MachineRegKeyPath -name:$MachineRegValueName -ErrorAction:SilentlyContinue;
        
         if ($regValue -ne $null)
         {
             $server = $regValue.DefaultSDKServiceMachine;
         }
     }

     if ($server -eq $null)
     {
         $server = “localhost”
     }

     return $server
    }

    function Get-InstallDirectory
    {
     # Get Install directory
     $SetupRegKeyPath = “HKLM:softwareMicrosoftMicrosoft Operations Manager3.0Setup”;
     $InstallDirRegValueName = “InstallDirectory”;

     $InstallDir = “$env:SystemDriveProgram FilesSystem Center Operations Manager 3.0”;

     $regvalue = $null;
     $regValue = Get-ItemProperty -path:$SetupRegKeyPath -name:$InstallDirRegValueName -ErrorAction:SilentlyContinue;
     if ($regvalue -ne $null)
     {
         $InstallDir = $regValue.InstallDirectory;
     }

     return $InstallDir
    }

     

    function New-Collection ( [type] $type )
    {
     $typeAssemblyName = $type.AssemblyQualifiedName;
     $collection = new-object “System.Collections.ObjectModel.Collection“1$typeAssemblyName“;
     return ,($collection);
    }

    # Load SDK dlls
    $server = Get-SDKServerName
    $InstallDir = Get-InstallDirectory
    $sdkDir = “$InstallDirSDK Binaries”
    echo “Loading SDK”
    $dummy = [System.Reflection.Assembly]::LoadFrom(“$sdkDirMicrosoft.EnterpriseManagement.OperationsManager.Common.dll”)
    $dummy = [System.Reflection.Assembly]::LoadFrom(“$sdkDirMicrosoft.EnterpriseManagement.OperationsManager.dll”)

    # Connect to management group
    echo “Connecting to management group”
    $managementGroup = [Microsoft.EnterpriseManagement.ManagementGroup]::Connect($server)
    $admin = $managementGroup.GetAdministration()

    echo “Getting agent managed computers”
    $agentManagedComputers = $admin.GetAllAgentManagedComputers()

    # Get list of agents to delete
    foreach ($name in $args)
    {
        echo “Checking for $name”
        foreach ($agent in $agentManagedComputers)
        {
            if ($deleteCollection -eq $null)
            {
                $deleteCollection = new-collection $agent.GetType()
            }

           
            if (@($agent.PrincipalName -eq $name))
            {
         echo “Matched $name”
                $deleteCollection.Add($agent)
                break
            }
        }
    }

    if ($deleteCollection.Count -gt 0)
    {
        echo “Deleting agents”
        $admin.DeleteAgentManagedComputers($deleteCollection)
        if($?){ echo “Agents deleted” }
    }

     

    Neue SCOM-Powershell:

    folgendes ausführen

    script.ps1 “serverFQDN”

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.