Author Posts

September 16, 2018 at 5:53 pm

Hi,
I am looking for a powershell script to delete 100+ Local user accounts from 50+ desktops that are in the Domain. Instead of logging into each individual PC's and deleting the users one by one, I prefer to run a powershell script from somewhere like the domain controller to delete the users from each of these desktops.

I have the details in an excel spreadsheet as below

[URL=http://img292.imagevenue.com/img.php?image=099541774_PowerShell_122_19lo.JPG][IMG]http://img292.imagevenue.com/loc19/th_099541774_PowerShell_122_19lo.JPG[/IMG][/URL]

Any other forums that you suggest, for me to get help regarding this?

September 16, 2018 at 6:18 pm

PowerShell is capable of doing this. But we would like you to try this. You need to find the way to do it locally first, then execute the same command against you target systems using PowerShell's remoting capability. Below documentations will help you.

  • Get-Help Invoke-Command -Full
  • ImportExcel module by Douge Finke

We will be here to help you when encountering problems with your script.

September 16, 2018 at 8:17 pm

Depending on what version of PS you are on, there are built-in cmdlet to do this for a single host.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/remove-localuser?view=powershell-5.1

Otherwise use this...

https://www.powershellgallery.com/packages/localaccount/1.4

As pointed out by , you then just need to run this for multiple computers by using a ForLoop targeting those remote systems using the noted cmdlet.

There are plenty of samples all over the web showing how to delete local user accounts.

https://berkenbile.wordpress.com/2013/04/26/manage-local-user-accounts-with-powershell/

Use PowerShell to remove local profiles

https://sysadminguides.org/2017/04/30/delete-local-user-profiles-remotely-using-a-powershell-script-delprof-exe/

 

 

 

 

September 19, 2018 at 10:43 am

It would be great if you update the post by formating the code using code posting tags , this makes other to easily understand your code, below link will help you.