PowerShell script to change the administrator password on a remote computer

Here's a PowerShell script to change the administrator password on a remote computer:

# Define the target computer and the new password $computer = "RemoteComputerName" $password = ConvertTo-SecureString "NewPassword" -AsPlainText -Force # Create a new PS credentials object $cred = New-Object System.Management.Automation.PSCredential("Administrator", $password) # Change the password on the remote computer Invoke-Command -ComputerName $computer -Credential $cred -ScriptBlock {net user Administrator $using:password}


This script uses the Invoke-Command cmdlet to run a command on a remote computer. The -ComputerName parameter is used to specify the target computer, and the -Credential parameter is used to pass the credentials of an administrative account. The script block contains the net user command to change the password of the administrator account. The password is stored in the $password variable, which is passed to the remote computer using the $using: syntax.

No comments:

Post a Comment