There are times when you may wish to automate deleting objects in SCOM. The safest method is always using the Console, or the SDK to delete objects in SCOM, in a manner they were designed to be deleted.
There is an option in the SCOM Console to delete discovered Network Devices
However, there is not a PowerShell command in SCOM to delete these objects.
Below, is an example of using a method from the Microsoft.EnterpriseManagement.Administration namespace, in PowerShell, which will allow you to do this.
It involves creating a Generic Collection/List, of the device type you wish to delete (Microsoft.EnterpriseManagement.Administration.RemotelyManagedDevice), then adding devices to the collection by using “GetAllRemotelyManagedDevices()”, then calling the method “DeleteRemotelyManagedDevices”
# Begin Network Device Delete #================================================================================= # Get SCOM directory for binaries $SCOMRegKey = "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup" $SCOMPath = (Get-ItemProperty $SCOMRegKey).InstallDirectory $SCOMPath = $SCOMPath.TrimEnd("\") $SCOMSDKPath = "$SCOMPath\SDK Binaries" #Load SDK binaries $dummy = [System.Reflection.Assembly]::LoadFrom("$SCOMSDKPath\Microsoft.EnterpriseManagement.Core.dll") $dummy = [System.Reflection.Assembly]::LoadFrom("$SCOMSDKPath\Microsoft.EnterpriseManagement.OperationsManager.dll") $dummy = [System.Reflection.Assembly]::LoadFrom("$SCOMSDKPath\Microsoft.EnterpriseManagement.Runtime.dll") # Connect to management group and load the Administration namespace $MG = [Microsoft.EnterpriseManagement.ManagementGroup]::Connect("localhost") $Admin = $MG.GetAdministration() # Define generic collection list which is the required parameter for the SDK delete command $RemotelyManagedDeviceType = [Microsoft.EnterpriseManagement.Administration.RemotelyManagedDevice]; $GenericListType = [System.Collections.Generic.List``1] $GenericList = $GenericListType.MakeGenericType($RemotelyManagedDeviceType) $NDList = new-object $GenericList.FullName # Get all Network Devices $NetworkDevices = $Admin.GetAllRemotelyManagedDevices() #Loop through each Network Device and add the ones we want to the generic list based on some criteria FOREACH ($NetworkDevice in $NetworkDevices) { #Example of using a specific displayname as the criteria to add to the list IF ($NetworkDevice.DisplayName -eq "PRN") { # Add our network device to the collection for deletion $NDList.Add($NetworkDevice) } } #Delete network devices $Admin.DeleteRemotelyManagedDevices($NDList) #================================================================================= # End Network Device Delete
You can adapt this to other device types available in the same namespace, documented here:
https://docs.microsoft.com/en-us/previous-versions/system-center/developer/bb438221(v=msdn.10)