Last active
March 15, 2017 21:02
-
-
Save ehershey/9d1f2d79c42fc59f3ca5b52f88cad0c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# windowsnewpass.sh | |
# | |
# Usage: windowsnewpass.sh [ <PASSWORD> ] | |
# | |
# A new password will be randomly generated if none is specified. | |
# The password can then be used for logging into the host via RDP. | |
# | |
# | |
if [ "$1" ] | |
then | |
password="$1" | |
if ! net user Administrator "$password" | |
then | |
echo "Setting password failed. Aborting" | |
exit 2 | |
fi | |
else | |
echo "Generating random password..." | |
# This command can sometimes fail | |
# | |
while ! net user Administrator /random > /tmp/rdp_password.out 2>&1 | |
do | |
echo "Retrying to generate sufficient random password." | |
done | |
echo "Done." | |
password="$(grep "Password for Administrator is:" /tmp/rdp_password.out | cut -f2 -d: | tr -d \ )" | |
fi | |
echo "Setting password on sshd service." | |
sc config sshd obj= '.\Administrator' password= "$password" | |
echo "Done." | |
echo "New password is: $password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment