PowerCLI: how to provide a password or credential for a guest OS which has no password set?

1

I want some system info of a guest OS, the script goes like this:

  $script = '&"$env:ProgramFiles\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report "$env:Tmp\inforeport"'

  Invoke-VMScript -ScriptText $script -VM $targetVM

unfortunately it failed with the error:

Invoke-VMScript     SSPI NTLM: InitializeSecurityContext failed for target 'PC\TOM'. Error code: 0x8009030E

PC\TOM is my username in my pc.

This clearly is due to a lack of credentials. But the guest OS doesn't have a password. I try to pass the guest OS username only:

Invoke-VMScript -ScriptText $script -VM $targetVM -GuestUser administrator

It failed undoubtly:Invoke-VMScript value cannot be null. Parameter name : s

So how to provide a password or credential for a guest OS which has no password set, if I don't want to manually log in the guest OS and set a password?

vmware
vsphere
powercli
asked on Stack Overflow Jun 16, 2017 by Wangwang

1 Answer

0

I received that message until I submitted "-GuestCredential"

$localCreds = Get-Credential
Invoke-VMScript -VM <vmname> -ScriptType Powershell -GuestCredential $localCreds -ScriptText $(Get-content .\theScript.ps1)
answered on Stack Overflow May 2, 2018 by Jake Nelson

User contributions licensed under CC BY-SA 3.0