The following Group Policy Preferences are affected by this change. Each preference is covered briefly and then in more detail. Additionally, workarounds are provided that enable you to perform the same tasks.
Affected preference | Applies to user
| Applies to computer
|
Local user management | Yes | Yes |
Mapped drives | Yes | No |
Services | No | Yes |
Scheduled tasks (up-level) | Yes | Yes |
Scheduled tasks (down-level) | Yes | Yes |
Immediate tasks (up-level) | Yes | Yes |
Immediate tasks (down-level) | Yes | Yes |
Data sources | Yes | Yes |
Summary of changes
- Password fields in all affected preferences are disabled. Administrators cannot create new preferences by using these password fields.
- The username field is disabled in some preferences.
- Existing preferences that contain a password cannot be updated. They can only be deleted or disabled, as appropriate for the specific preference.
- The behavior for Delete and Disable actions have not changed for the preferences.
- When an administrator opens any preference that contains the CPassword attribute, the administrator receives the following warning dialog box to inform him or her of the recent deprecation. Attempts to save changes to new or existing preferences that require the CPassword attribute will trigger the same dialog box. Only Delete and Disable actions will not trigger warning dialog boxes.
Scenario 1: Local user management
The Local User Management preference is frequently used to create local administrators who have a known password on a computer. This feature is not secure because of the way that Group Policy Preferences stores passwords. Therefore, this functionality is no longer available. The following preferences are affected:
- Computer Configuration -> Control Panel Settings -> Local Users and Groups-> New-> Local User
- User Configuration -> Control Panel Settings -> Local Users and Groups-> New-> Local User
Important changes
Action: Create or Replace - The User name, Password, and Confirm Password fields are disabled.
- The warning dialog box appears when the administrator opens or tries to save any changes to an existing preference that contains a password.
Action: Update - The Password and Confirm Password fields are disabled.
- The warning dialog box appears when the administrator opens or tries to save any changes to an existing preference that contains a password.
Action: Delete Workarounds
For those who previously relied on the Group Policy Preference for setting local administrator passwords, the following script is provided as a secure alternative to CPassword. Copy and save the contents to a new Windows PowerShell file, and then run the script as indicated in its .EXAMPLE section.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
function Invoke-PasswordRoll
{
<#
.SYNOPSIS
This script can be used to set the local account passwords on remote machines to random passwords. The username/password/server combination will be saved in a CSV file.
The account passwords stored in the CSV file can be encrypted using a password of the administrators choosing to ensure clear-text account passwords aren't written to disk.
The encrypted passwords can be decrypted using another function in this file: ConvertTo-CleartextPassword
Function: Invoke-PasswordRoll
Author: Microsoft
Version: 1.0
.DESCRIPTION
This script can be used to set the local account passwords on remote machines to random passwords. The username/password/server combination will be saved in a CSV file.
The account passwords stored in the CSV file can be encrypted using a password of the administrators choosing to ensure clear-text account passwords aren't written to disk.
The encrypted passwords can be decrypted using another function in this file: ConvertTo-CleartextPassword
.PARAMETER ComputerName
An array of computers to run the script against using PowerShell remoting.
.PARAMETER LocalAccounts
An array of local accounts whose password should be changed.
.PARAMETER TsvFileName
The file to output the username/password/server combinations to.
.PARAMETER EncryptionKey
A password to encrypt the TSV file with. Uses AES encryption. Only the passwords stored in the TSV file will be encrypted, the username and servername will be clear-text.
.PARAMETER PasswordLength
The length of the passwords which will be randomly generated for local accounts.
.PARAMETER NoEncryption
Do not encrypt the account passwords stored in the TSV file. This will result in clear-text passwords being written to disk.
.EXAMPLE
. .\Invoke-PasswordRoll.ps1 #Loads the functions in this script file
Invoke-PasswordRoll -ComputerName (Get-Content computerlist.txt) -LocalAccounts @("administrator","CustomLocalAdmin") -TsvFileName "LocalAdminCredentials.tsv" -EncryptionKey "Password1"
Connects to all the computers stored in the file "computerlist.txt". If the local account "administrator" and/or "CustomLocalAdmin" are present on the system, their password is changed
to a randomly generated password of length 20 (the default). The username/password/server combinations are stored in LocalAdminCredentials.tsv, and the account passwords are AES encrypted using the password "Password1".
.EXAMPLE
. .\Invoke-PasswordRoll.ps1 #Loads the functions in this script file
Invoke-PasswordRoll -ComputerName (Get-Content computerlist.txt) -LocalAccounts @("administrator") -TsvFileName "LocalAdminCredentials.tsv" -NoEncryption -PasswordLength 40
Connects to all the computers stored in the file "computerlist.txt". If the local account "administrator" is present on the system, its password is changed to a random generated
password of length 40. The username/password/server combinations are stored in LocalAdminCredentials.tsv unencrypted.
.NOTES
Requirements:
-PowerShellv2 or above must be installed
-PowerShell remoting must be enabled on all systems the script will be run against
Script behavior:
-If a local account is present on the system, but not specified in the LocalAccounts parameter, the script will write a warning to the screen to alert you to the presence of this local account. The script will continue running when this happens.
-If a local account is specified in the LocalAccounts parameter, but the account does not exist on the computer, nothing will happen (an account will NOT be created).
-The function ConvertTo-CleartextPassword, contained in this file, can be used to decrypt passwords that are stored encrypted in the TSV file.
-If a server specified in ComputerName cannot be connected to, PowerShell will output an error message.
-Microsoft advises companies to regularly roll all local and domain account passwords.
#>
[CmdletBinding(DefaultParameterSetName="Encryption")]
Param(
[Parameter(Mandatory=$true)]
[String[]]
$ComputerName,
[Parameter(Mandatory=$true)]
[String[]]
$LocalAccounts,
[Parameter(Mandatory=$true)]
[String]
$TsvFileName,
[Parameter(ParameterSetName="Encryption", Mandatory=$true)]
[String]
$EncryptionKey,
[Parameter()]
[ValidateRange(20,120)]
[Int]
$PasswordLength = 20,
[Parameter(ParameterSetName="NoEncryption", Mandatory=$true)]
[Switch]
$NoEncryption
)
#Load any needed .net classes
Add-Type -AssemblyName "System.Web" -ErrorAction Stop
#This is the scriptblock that will be executed on every computer specified in ComputerName
$RemoteRollScript = {
Param(
[Parameter(Mandatory=$true, Position=1)]
[String[]]
$Passwords,
[Parameter(Mandatory=$true, Position=2)]
[String[]]
$LocalAccounts,
#This is here so I can record what the server name that the script connected to was, sometimes the DNS records get messed up, it can be nice to have this.
[Parameter(Mandatory=$true, Position=3)]
[String]
$TargettedServerName
)
$LocalUsers = Get-WmiObject Win32_UserAccount -Filter "LocalAccount=true" | Foreach {$_.Name}
#Check if the computer has any local user accounts whose passwords are not going to be rolled by this script
foreach ($User in $LocalUsers)
{
if ($LocalAccounts -inotcontains $User)
{
Write-Warning "Server: '$($TargettedServerName)' has a local account '$($User)' whos password is NOT being changed by this script"
}
}
#For every local account specified that exists on this server, change the password
$PasswordIndex = 0
foreach ($LocalAdmin in $LocalAccounts)
{
$Password = $Passwords[$PasswordIndex]
if ($LocalUsers -icontains $LocalAdmin)
{
try
{
$objUser = [ADSI]"WinNT://localhost/$($LocalAdmin), user"
$objUser.psbase.Invoke("SetPassword", $Password)
$Properties = @{
TargettedServerName = $TargettedServerName
Username = $LocalAdmin
Password = $Password
RealServerName = $env:computername
}
$ReturnData = New-Object PSObject -Property $Properties
Write-Output $ReturnData
}
catch
{
Write-Error "Error changing password for user:$($LocalAdmin) on server:$($TargettedServerName)"
}
}
$PasswordIndex++
}
}
#Generate the password on the client running this script, not on the remote machine. System.Web.Security isn't available in the .NET Client profile. Making this call
# on the client running the script ensures only 1 computer needs the full .NET runtime installed (as opposed to every system having the password rolled).
function Create-RandomPassword
{
Param(
[Parameter(Mandatory=$true)]
[ValidateRange(20,120)]
[Int]
$PasswordLength
)
$Password = [System.Web.Security.Membership]::GeneratePassword($PasswordLength, $PasswordLength / 4)
#This should never fail, but I'm putting a sanity check here anyways
if ($Password.Length -ne $PasswordLength)
{
throw new Exception("Password returned by GeneratePassword is not the same length as required. Required length: $($PasswordLength). Generated length: $($Password.Length)")
}
return $Password
}
#Main functionality - Generate a password and remote in to machines to change the password of local accounts specified
if ($PsCmdlet.ParameterSetName -ieq "Encryption")
{
try
{
$Sha256 = new-object System.Security.Cryptography.SHA256CryptoServiceProvider
$SecureStringKey = $Sha256.ComputeHash([System.Text.UnicodeEncoding]::Unicode.GetBytes($EncryptionKey))
}
catch
{
Write-Error "Error creating TSV encryption key" -ErrorAction Stop
}
}
foreach ($Computer in $ComputerName)
{
#Need to generate 1 password for each account that could be changed
$Passwords = @()
for ($i = 0; $i -lt $LocalAccounts.Length; $i++)
{
$Passwords += Create-RandomPassword -PasswordLength $PasswordLength
}
Write-Output "Connecting to server '$($Computer)' to roll specified local admin passwords"
$Result = Invoke-Command -ScriptBlock $RemoteRollScript -ArgumentList @($Passwords, $LocalAccounts, $Computer) -ComputerName $Computer
#If encryption is being used, encrypt the password with the user supplied key prior to writing to disk
if ($Result -ne $null)
{
if ($PsCmdlet.ParameterSetName -ieq "NoEncryption")
{
$Result | Select-Object Username,Password,TargettedServerName,RealServerName | Export-Csv -Append -Path $TsvFileName -NoTypeInformation
}
else
{
#Filters out $null entries returned
$Result = $Result | Select-Object Username,Password,TargettedServerName,RealServerName
foreach ($Record in $Result)
{
$PasswordSecureString = ConvertTo-SecureString -AsPlainText -Force -String ($Record.Password)
$Record | Add-Member -MemberType NoteProperty -Name EncryptedPassword -Value (ConvertFrom-SecureString -Key $SecureStringKey -SecureString $PasswordSecureString)
$Record.PSObject.Properties.Remove("Password")
$Record | Select-Object Username,EncryptedPassword,TargettedServerName,RealServerName | Export-Csv -Append -Path $TsvFileName -NoTypeInformation
}
}
}
}
}
function ConvertTo-CleartextPassword
{
<#
.SYNOPSIS
This function can be used to decrypt passwords that were stored encrypted by the function Invoke-PasswordRoll.
Function: ConvertTo-CleartextPassword
Author: Microsoft
Version: 1.0
.DESCRIPTION
This function can be used to decrypt passwords that were stored encrypted by the function Invoke-PasswordRoll.
.PARAMETER EncryptedPassword
The encrypted password that was stored in a TSV file.
.PARAMETER EncryptionKey
The password used to do the encryption.
.EXAMPLE
. .\Invoke-PasswordRoll.ps1 #Loads the functions in this script file
ConvertTo-CleartextPassword -EncryptionKey "Password1" -EncryptedPassword 76492d1116743f0423413b16050a5345MgB8AGcAZgBaAHUAaQBwADAAQgB2AGgAcABNADMASwBaAFoAQQBzADEAeABjAEEAPQA9AHwAZgBiAGYAMAA1ADYANgA2ADEANwBkADQAZgAwADMANABjAGUAZQAxAGIAMABiADkANgBiADkAMAA4ADcANwBhADMAYQA3AGYAOABkADcAMQA5ADQAMwBmAGYANQBhADEAYQBjADcANABkADIANgBhADUANwBlADgAMAAyADQANgA1ADIAOQA0AGMAZQA0ADEAMwAzADcANQAyADUANAAzADYAMAA1AGEANgAzADEAMQA5ADAAYwBmADQAZAA2AGQA"
Decrypts the encrypted password which was stored in the TSV file.
#>
Param(
[Parameter(Mandatory=$true)]
[String]
$EncryptedPassword,
[Parameter(Mandatory=$true)]
[String]
$EncryptionKey
)
$Sha256 = new-object System.Security.Cryptography.SHA256CryptoServiceProvider
$SecureStringKey = $Sha256.ComputeHash([System.Text.UnicodeEncoding]::Unicode.GetBytes($EncryptionKey))
[SecureString]$SecureStringPassword = ConvertTo-SecureString -String $EncryptedPassword -Key $SecureStringKey
Write-Output ([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($SecureStringPassword)))
}
Administrators can add local administrator accounts to computers by creating an Active Directory group and adding it to the local Administrators group through Group Policy Preferences -> Local Group. This action does not cache credentials. The dialog box resembles the following. This workaround does require a connection to Active Directory Domain Services when the user is logged on by using these credentials.
Scenario 2: Mapped drives
Administrators use drive maps to allocate network locations to users. The password protection feature is used to make sure of authorized access to the drive. The following preferences are affected:
- User Configuration -> Windows Settings -> Drive Maps -> New -> Mapped Drive
Important changes
Action: Create, Update, or Replace - The User name, Password, and Confirm password fields are disabled.
Action: Delete Workarounds
Instead of using the password method for authentication, you can use Windows Explorer to manage share permissions and allocate rights to users. You can use Active Directory objects to control permissions to the folder.
Scenario 3: Services
You can use the Services preference to change service properties in such a way that they run in a context other than their original security context. The following preferences are affected:
- Computer Configuration -> Control Panel Settings -> Services -> New -> Service
Important changes
Startup: No Change, Automatic, or Manual - The Password and Confirm password fields are disabled.
- The administrator can use only built-in accounts.
Startup: Disable New dialog box- Administrators who try to use non-built-in users for This account" receive the following warning:
Workarounds
Services can still run as a local system account. Service permissions can be altered as documented in the following article in the Microsoft Knowledge Base:
256345 How to Configure Group Policy settings to set security for system services
Note If the service that you want to configure is not present, you must configure the settings on a computer that has the service running.
Scenario 4: Scheduled and immediate tasks (up-level)
These are used to run scheduled tasks in a specific security context. The ability to store credentials for scheduled tasks to run as an arbitrary user when that user is not logged on is no longer available. The following preferences are affected. (Be aware that on some platforms, "At least Windows 7" is replaced with "Windows Vista and later.")
- Computer Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Task (At least Windows 7)
- Computer Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Immediate Task (At least Windows 7)
- User Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Task (At least Windows 7)
- User Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Immediate Task (At least Windows 7)
Important changes
Action: Create, Update, or Replace - When you select the Run whether user is logged on or not option, a dialog box no longer prompts the administrator for credentials.
- The Do not store password check box is disabled. By default, the box is also checked.
Action: Delete No change in behavior
Workarounds
For the "Scheduled Task (at least Windows 7)" and "Immediate Task (at least Windows 7)" tasks, administrators can use specific user accounts when the given user is logged on. Or, they can only have access to local resources as that user. These tasks still can run in the context of the local service.
Scenario 5: Scheduled and immediate tasks (down-level)
This is the down-level version of preferences used to run Scheduled Tasks in a specific security context. The ability to store credentials for scheduled tasks to run as an arbitrary user when that user is not logged on is no longer available. The following preferences are affected:
- Computer Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Task
- Computer Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Immediate Task (Windows XP)
- User Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Task
- User Configuration -> Control Panel Settings -> Scheduled Tasks -> New -> Immediate Task (Windows XP)
Important changes
Action: Create, Update, or Replace - The Run as check box is disabled. Therefore, the User Name, Password, and Confirm Password fields are all disabled.
Action: Delete No change in behavior
Workarounds
For the "Scheduled Task" and "Immediate Task (Windows XP)" items, scheduled tasks run by using the permissions that are currently available to the local service.
Scenario 6: Data Sources
The Data Sources preference is used to associate a data source with a computer or user. This feature no longer stores credentials to enable access to data sources that are protected by a password. The following preferences are affected:
- Computer Configuration -> Control Panel Settings -> Data Sources
- User Configuration -> Control Panel Settings -> Data Sources
Important Changes
Action: Create, Update, or Replace - The User Name, Password, and Confirm Password fields are disabled:
Action: Delete Workarounds
No workarounds are available. This preference no longer stores credentials to allow access to data sources that are protected by a password.