Universal Object Removal Script (removealluniversal.ps1) v1.1
For more information, see: 
https://vswitchzero.com/2018/11/16/removing-all-universal-objects-using-powernsx-and-powershell-scripting/

This script will remove all universal objects from an NSX manager. It should only be used with NSX managers in the 'Transit' role.

WARNING/DISCLAIMER: No warranty or guarantees are provided with this script. Although it has been tested to function correctly, use it at your own risk.

Pre-requisites:
1. A recent version of PowerShell, VMware PowerCLI (10.x or later) and PowerNSX (3.0.x or later) are required for this script to function.
2. Be sure to launch PowerShell as an administrator if using Microsoft Windows.
3. Before launching the script, you will need to connect to the Transit NSX manager and it's associated vCenter Server. You can use the Connect-NsxServer cmdlet for this purpose.
4. Because this script will execute against the NSX manager connected to, please ensure that you are connected to the correct 'Transit' NSX Manager and associated vCenter before proceeding.
5. It is strongly recommended that a backup of both the primary and transit NSX manager be taken before proceeding. 

The script does the following:

1. Displays a warning message about taking backups prior to executing the script and confirms you want to proceed.
2. As a safety precaution, it checks to ensure you’re connected to a ‘Transit’ role manager before proceeding. The script will end if you are connected to a primary/secondary or standalone manager.
3. Runs several ‘Get’ cmdlets to obtain a total count of all universal objects on the connected NSX manager.
4. Asks you if you want to proceed to remove all objects.
5. Removes all universal objects of all types and in the correct order. The script will report how many objects were removed along the way.
6. When finished, it will display a new count of all objects for comparison purposes.

Note: It is expected to see non-zero counts for both Universal Service Groups and Services as there are internal read-only objects that can't be removed. 
Only user-created objects will be removed using this script. 

If all other counts are zero after running the script, you can attempt to change the NSX Manager's role from Transit to Standalone.

