
You can run this PowerShell script via a GPO at shutdown or with a PowerShell script in Task Scheduler. Write-host $LocalProfile.LocalPath, "profile deleted” -ForegroundColor Magenta Best Regards, Please remember to mark the replies as answers if they help.

Run the Registry Editor ( regedit.exe) Select Open PowerShell Window Here on Windows 10 or Open Command Windows Here.In this case, you will need to manually delete the profile reference from the Windows registry: Many novice administrators try to manually remove the user profile directory from the C:\Users folder. You can restore the deleted user account within 30 days.įirst, connect to your Microsoft 365 tenant.When a user profile is properly deleted in Windows, the profile directory in C:\Users and the user entry in the registry are deleted. When you delete a user account through the Microsoft Azure Active Directory Module for Windows PowerShell, the account isn't permanently deleted. Use the Microsoft Azure Active Directory Module for Windows PowerShell

Write-Host (Get-AzureADUser | where ).UserPrincipalName Now, click on the corrupted user profile and click on Remove.

To display the account name based on the user's name, use the following commands: $userName="" Press Windows key + R, to open Run dialog box. The -ObjectID parameter in the Remove-AzureADUser cmdlet accepts either the account's sign-in name, also known as the User Principal Name or the account's object ID.
