- 1 year ago
How to delete a Server from SCCM from local PowerShell script
To delete a server from SCCM (System Center Configuration Manager) using a local PowerShell script, you can use the SCCM PowerShell module called "ConfigurationManager". Here's an example of how you can accomplish this:
Install SCCM PowerShell Module: Ensure that you have the SCCM PowerShell module installed on the machine where you're running the script. You can download and install it from the Microsoft Download Center or install it from the SCCM installation media.
Import the SCCM Module: In your PowerShell script, import the SCCM module by running the following command:
powershellImport-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')
Connect to the SCCM Site: Connect to the SCCM site using the
Connect-CMManagementPoint
cmdlet. Provide the necessary parameters, such as the site code and management point server name. For example:powershellConnect-CMManagementPoint -SiteCode "ABC" -Server "SCCMServer"
Get the Server Resource: Use the
Get-CMDevice
cmdlet to retrieve the server resource from SCCM. You can filter by server name or any other relevant criteria. For example:powershell$server = Get-CMDevice -Name "ServerName"
Delete the Server: Finally, use the
Remove-CMDevice
cmdlet to delete the server resource from SCCM. Pass the$server
object obtained in the previous step. For example:powershellRemove-CMDevice -DeviceId $server.DeviceID
By executing these steps in your PowerShell script, you will be able to delete a server from SCCM using the SCCM PowerShell module. Make sure you have the necessary permissions to perform the deletion operation in SCCM. Adjust the filtering and selection criteria as needed based on your SCCM environment and requirements.