Here's what I use to set the local admin password:

 Code:
$sNewPassword = "YourSuperSecretPasswordGoesHere!"
$sAdminName = GetAdministratorName
$oUser = GetObject("WinNT://" + @WKSTA + "/" + $sAdminName + ",user")
$oUser.SetPassword($sNewPassword)
$oUser.SetInfo

Function GetAdministratorName()
  Dim $sUserSID, $oWshNetwork, $oUserAccount
  $oWshNetwork = CreateObject("WScript.Network")
  $oUserAccounts = GetObject("winmgmts://" + $oWshNetwork.ComputerName + "/root/cimv2").ExecQuery("Select Name, SID from Win32_UserAccount" + " WHERE Domain = '" + $oWshNetwork.ComputerName + "'")
  For Each $oUserAccount In $oUserAccounts
    If Left($oUserAccount.SID, 9) = "S-1-5-21-" And Right($oUserAccount.SID, 4) = "-500"
      $GetAdministratorName = $oUserAccount.Name
    EndIf
  Next
EndFunction

I tokenize the script (read the manual about that) and call it from the main login script so the admin password isn't hanging around in plain text.

It can also be set via GPO, which is probably a better way to go.


Edited by eriqjaffe (2010-01-29 04:39 PM)