Category filter
Script to enable or disable Microsoft accounts on Windows 10
Users sign in to their Windows devices using either a Local account or a Microsoft Account. Though these accounts are often created for a user by the administrators, they may choose to defer logins using these accounts. Unlike a Local account, the Microsoft Account needs to be responsibly handled because it lets users sync data and settings, making it easier to access this information anytime and vulnerable to hacking. The following PowerShell scripts help you disable the Microsoft accounts existing on Windows 10 devices. Then, with the help of Execute Custom Script action, you can quickly execute them on the devices.
Disable Microsoft Accounts on Windows
If you choose to disable all the Microsoft Accounts existing on the devices, the following script helps.
1 2 3 4 5 6 7 |
$new = Get-LocalUser | Select-Object -Property Name, PrincipalSource, Enabled foreach($u in $new) { if($u.PrincipalSource -eq ‘MicrosoftAccount’) { Write-Output $u.Name Disable-LocalUser -Name $u.Name }} |
Alternatively, you can get all the Microsoft Accounts re-enabled using the script below.
1 2 3 4 5 6 7 |
$new = Get-LocalUser | Select-Object -Property Name, PrincipalSource, Enabled foreach($u in $new) { if($u.PrincipalSource -eq ‘MicrosoftAccount’) { Write-Output $u.Name Enable-LocalUser -Name $u.Name }} |
Disable a specific Microsoft user account on Windows
To disable any existing user account on the device, all you have to do is replace the value “User” with the corresponding account name in the following script and execute it from the console.
1 |
Disable-LocalUser -Name "User" |
For example, provide the name of the account as in
Disable-LocalUser -Name "Serah"
You can fetch the actual name of the user by running this command:
Get-LocalUser
Also, re-enabling the given user account is relatively simpler. You may use the following script to achieve it.
1 |
Enable-LocalUser -Name "User" |