Home Service Manager

Delete User Via Powershell

Nathan_ErdmanNathan_Erdman Customer IT Monkey ✭
I need to delete a few users from the CMDB and the Deleted items view has errored out for quite some time. Anyone know of a Powershell to delete users?

Answers

  • Peter_SettlePeter_Settle Customer Advanced IT Monkey ✭✭✭

    hI

    Just found this post from @joe_burrows hope it helps.......

    In which case you will need to manually remove the stale objects from the service management database. 

    Example: (Just replace with the old username)

    DELETE
      FROM [ServiceManagement].[dbo].[CI$User]
      WHERE [username] = 'joe.burrows'

    Then restart your cachebuilder.
  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    That SQL script will only remove users from the Cireson Portal cache.

    To remove users from the CMDB, you need to use the SMLets Remove-SCSMObject cmdlet.

    Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.AD.User$) -Filter "UserName -eq 'joesoap'" | Remove-SCSMObject -Force


  • Narmin_HemnaniNarmin_Hemnani Customer IT Monkey ✭
    Can anyone please confirm that the above 2 tasks (i.e. the delete user from sql and the powershell) work as expected. And there is no potential for orphan records by performing the tasks to delete the user record? Thanks
  • Davin_ClouthierDavin_Clouthier Customer Adept IT Monkey ✭✭
    I can confirm that john_doyle's method works and have no orphan record issues we have been using something similar in our environment for some time now.
  • Narmin_HemnaniNarmin_Hemnani Customer IT Monkey ✭

    Thank you for your quick response

Sign In or Register to comment.