Intune – Remove User – Remove-LocalUser : The term ‘Remove-LocalUser’ is not recognized as the name of a cmdlet, function, script file

I tried to use PowerShell script via Intune that remove my user from Windows Endpoint using powershell command

Remove-LocalUser -Name “myuser”.

It was not working, just because:

, error = Remove-LocalUser : The term ‘Remove-LocalUser’ is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At C:\Program Files (x86)\Microsoft Intune Management
Extension\Policies\Scripts\05b2518c-c36d-4a05-84f7-6fac956d4cc6_c293361b-b3d3-48d9-8aca-f8ccf0a11330.ps1:1 char:1
+ Remove-LocalUser -Name “myuser”
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Remove-LocalUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

So the workaround is using this:

“net user myuser /DELETE”|cmd

All script:

$op = Get-LocalUSer | where-Object Name -eq “myuser” | Measure
if ($op.Count -eq 0) {
Write-Host “No User to Remove”
} else {
“net user myuser /DELETE”|cmd
Write-Host “User myuser has been Removed”
}