Remove-SPManagedAccount failing after user was removed from Active Directory, in SharePoint 2013

Today I did a small mistake, I deleted an AD user before removing it first from the list of Managed accounts in SharePoint 2013. To be more specific about my case, the managed account was not used for anything, but still I was not able to delete it from the list of managed accounts after I deleted the AD account.

I was lucky to find a comment on one blog about a way to solve this  so I am sharing this with you. The person who posted the comment is called Jonathan Manley so all credits go to him. 

The solution is to use:

Get-SPManagedAccount -identity “domain\accountname” |Remove-SPManagedAccount