2015-10-29 1 views
2

J'ai une version modifiée de ce script PowerShell: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/355d9293-e324-4f60-8eed-18bcc6d67fc0/adsiwinntcomputeradministratoruser-with-alternate-credentials?forum=ITCGpeut ADSI être utilisé pour définir un mot de passe pour le compte Windows nécessitant le changement à la première connexion

Il échoue en essayant de changer le mot de passe pour un compte avec une première exigence d'ouverture de session (que je peux changer le mot de passe manuellement en utilisant l'invite ctrl + alt + del, mais je l'exécuterai souvent pour tester la VM sur l'image). La partie qui compte est:

Invoke-Command -ComputerName $ComputerName -Credential $Credential -ErrorVariable e -ArgumentList $ComputerName,$NewPassword,$User -ScriptBlock { 
      Param($ComputerName,$NewPassword,$User) 
      $Account = [ADSI]"WinNT://$ComputerName/$User,user" 
      $Account.PwdLastSet = 0 
      $Account.SetInfo() 
      $Account.SetPassword($NewPassword) 
      $Account.SetInfo() 
      $e 
     } 

Quand je lance ce pour un compte qui ne nécessite pas de changement à la première connexion, il se termine avec succès:

> Change-LocalPassword -User 'TestAccount' -Credential $wincred -OldPassword $OP -NewPassword $NP -ComputerName $computerName 
Info::Change-LocalPassword::Changing password from <old> to <new> 
Info::Change-LocalPassword::Service WinRM is already running on Localhost 
Info::Change-LocalPassword::Trusted Hosts Value is: <computer> 
Info::Change-LocalPassword Invoking Command: [adsi]WinNT://<computer>/TestAccount,user 
True 

Lors de l'exécution pour le compte nécessitant la première connexion:

Change-LocalPassword -User $Config.win_user -Credential $wincred -OldPassword $Config.winog_passwd -NewPassword $Config.win_passwd -ComputerName $computerName 
Info::Change-LocalPassword::Changing password from <old> to <new> 
Info::Change-LocalPassword::Service WinRM is already running on Localhost 
Info::Change-LocalPassword::Trusted Hosts Value is: <computer> 
Info::Change-LocalPassword Invoking Command: [adsi]WinNT://<computer>/<user>,user 
[computer] Connecting to remote server <computer> failed with the following error message : Access is denied. For more information, see 
the about_Remote_Troubleshooting Help topic. 
    + CategoryInfo   : OpenError: (<computer>:String) [], PSRemotingTransportException 
    + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken 
-Message Error::Change-LocalPassword::Could not set password for <user> on <computer> [computer] Connecting to remote server <computer> failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. 
False 

Le compte d'administrateur local est le seul compte sur la machine et n'est pas joint au domaine. Est-ce que quelqu'un d'autre a rencontré cela et a identifié une résolution?

Répondre

1

Ajouter un mot de passe ne userflag a expiré:

$Account = [ADSI]"WinNT://$ComputerName/$User,user" 
     $Account.UserFlags = 65536 
     $Account.PwdLastSet = 0 
     $Account.SetInfo() 
     $Account.SetPassword($NewPassword) 
     $Account.SetInfo() 

si vous voulez ajouter « utilisateur ne peut pas changer le mot de passe » et, remplacez la ligne ci-dessus avec celui-ci:

$Account.UserFlags = 64 + 65536 
+0

Il semble que je suis en quelque sorte d'une dépendance circulaire. Le seul compte sur la machine est le compte dont je tente de changer le mot de passe. Faire une commande invoke simple échoue avec l'accès refusé en utilisant les informations d'identification (en supposant que le mot de passe doit d'abord être changé): – user5505180

+0

'PS D: \ projets \ windows-cloudify> Invoke-Command -ComputerName $ computerName -Credential $ wincred -ScriptBlock {ls c: \ TEMP} [ordinateur] La connexion au serveur distant a échoué avec le message d'erreur suivant: L'accès est refusé. Pour plus d'informations, voir la rubrique d'aide about_Remote_Troubleshooting. + CategoryInfo: OpenError: (ordinateur: Chaîne) [], PSRemotingTransportException + FullyQualifiedErrorId: AccessDenied, PSSessionStateBroken' – user5505180