Arik
Arik

Reputation: 1257

Change guest password using pyvmomi

I am using pyVmomi for my automation. Now I am testing a VM, where the SSH is disabled by default, and I must change the password upon the first login:

You are required to change your password immediately (root enforced)

If I try connecting using pyVmomi's StartProgramInGuest, I get vim.fault.InvalidGuestLogin exception:

Failed to authenticate with the guest operating system using the supplied credentials

I am looking for a way to change the default password programmatically, (preferably) using pyVmomi

Upvotes: 1

Views: 1039

Answers (1)

basic197
basic197

Reputation: 43

To start off, it seems like you failed to pass the correct credentials when calling the "StartProgramInGuest" function, you can specify and pass credentials to this function using Name-Password authentication, like below.

creds = vim.vm.guest.NamePasswordAuthentication(username='username', password='password)

Test this and make sure you successfully authenticated to the guest virtual machine. After you're able to successfully authenticate, you can use Process Manager, to create either a Linux process or Windows process to change your password. For example, here is a PowerShell process tested on a Windows 10 virtual machine, executed through StartProgramInGuest.

 argument= vim.vm.guest.ProcessManager.ProgramSpec(programPath='powershell.exe -Command', arguments='"& {net user  loginid  newpassword;}"')
 res = pm.StartProgramInGuest(vm, creds, argument)

Let me know if you need any clarification!

Upvotes: 0

Related Questions