We have some PowerShell script to manage servers,
recently some of them do not work on newly deployed servers.
Here is any sample:
$script = "hostname"
Invoke-VMScript -vm MyServer -ScriptText $script
this used to work good and still working on old servers, the script will use current windows user credential.
but when running on newly deployed servers. We got following error:
Invoke-VMScript Error occurred while executing script on guest OS in VM 'MyServer'. Could not locate "Powershell" script interpreter in any of the expected locations. Probably
you do not have enough permissions to execute command within guest.
We have a workaround like this, but it needs user input and we always try to make things fully automatic
$Creds = Get-Credential "$env:USERDNSDOMAIN/$env:USERNAME"
$script = "hostname"
Invoke-VMScript -vm MyServer -ScriptText $script -GuestCredential $Creds
please help, thank you
Here is some log:
[2019-09-03T07:44:28.017Z] [ debug] [vmsvc] RpcIn: received 624 bytes, content:"Vix_1_Relayed_Command "56e4594565a63349"\00\01\00\0d衆05\00G\02\00\003\00\00\00郳01\00\004\00\00\00\0d筡00\00\00\00\00\00\00..."
[2019-09-03T07:44:28.017Z] [ message] [vix] VixTools_ProcessVixCommand: command 185
[2019-09-03T07:44:28.017Z] [ debug] [vix] VixToolsImpersonateUser: successfully impersonated user MyName
[2019-09-03T07:44:28.017Z] [ debug] [vix] VixTools_StartProgram: User: MyName args: progamPath: 'cmd.exe', arguments: '/C powershell -NonInteractive -EncodedCommand cABvAHcAZQByAHMAaABlAGwAbAAuAGUAeABlACAALQBPAHUAdABwAHUAdABGAG8AcgBtAGEAdAAgAHQAZQB4AHQAIAAtAE4AbwBuAEkAbgB0AGUAcgBhAGMAdABpAHYAZQAgAC0AQwBvAG0AbQBhAG4AZAAgACcAJgAgAHsAaABvAHMAdABuAGEAbQBlAH0AJwAgAD4AIAAiAEMAOgBcAFUAcwBlAHIAcwBcAHoAaABnAG8AbgBnAC0AYQBcAEEAcABwAEQAYQB0AGEAXABMAG8AYwBhAGwAXABUAGUAbQBwAFwAcABvAHcAZQByAGMAbABpAHYAbQB3AGEAcgBlADIANwAiADsAIABlAHgAaQB0ACAAJABsAGEAcwB0AGUAeABpAHQAYwBvAGQAZQA=', workingDir: ''
[2019-09-03T07:44:28.017Z] [ message] [VCGA] Pref_Init: Using 'C:\ProgramData\VMware\VMware VGAuth\vgauth.conf' as preferences filepath
[2019-09-03T07:44:28.017Z] [ debug] [VCGA] Pref_GetBool: Pref_GetBool(auditSuccessEvents) failed: Key file does not have group 'auditing'
[2019-09-03T07:44:28.017Z] [ debug] [VCGA] I18n_BindTextDomain: user locale=en_US
[2019-09-03T07:44:28.017Z] [ message] [VCGA] VGAuth 'build-12385171' initialized for application 'vmtoolsd'. Context created at 000001F59C31E6B0
[2019-09-03T07:44:28.017Z] [ debug] [vix] VixToolsTranslateVGAuthError: translated VGAuth err 0x2 to Vix err 3
[2019-09-03T07:44:28.017Z] [ warning] [vix] VixToolsStartProgramImpl: Failed to get user token
[2019-09-03T07:44:28.017Z] [ debug] [vix] GuestAuthUnloadUserProfileAndToken: special-case profile unload 0000000000000000
[2019-09-03T07:44:28.017Z] [ warning] [vix] GuestAuthUnloadUserProfileAndToken: UnloadUserProfile() failed 6
[2019-09-03T07:44:28.017Z] [ debug] [vix] VixTools_StartProgram: returning '-1'
[2019-09-03T07:44:28.017Z] [ message] [vix] VixTools_StartProgram: opcode 185 returning 3
[2019-09-03T07:44:28.017Z] [ debug] [vix] ToolsDaemonTcloReceiveVixCommand: command 185, additionalError = 0
[2019-09-03T07:44:28.017Z] [ debug] [vmsvc] RpcIn: sending 10 bytes
[2019-09-03T07:44:28.314Z] [ debug] [vmsvc] RpcIn: received 206 bytes, content:"Vix_1_Relayed_Command "56e45946ba7551cf"\00\01\00\0d衆05\0000\00\003\00\00\00>\00\00\004\00\00\00\05耚00\00\00\00\01\00\00..."
[2019-09-03T07:44:28.314Z] [ message] [vix] VixTools_ProcessVixCommand: command 194
[2019-09-03T07:44:28.314Z] [ debug] [vix] VixToolsImpersonateUser: successfully impersonated user MyName
[2019-09-03T07:44:28.314Z] [ debug] [vix] VixToolsDeleteObject: User: MyName path: 'C:\Users\ MyName\AppData\Local\Temp\powerclivmware27'
[2019-09-03T07:44:28.314Z] [ message] [vix] VixToolsDeleteObject: opcode 194 returning 0
[2019-09-03T07:44:28.314Z] [ debug] [vix] ToolsDaemonTcloReceiveVixCommand: command 194, additionalError = 0
[2019-09-03T07:44:28.314Z] [ debug] [vmsvc] RpcIn: sending 8 bytes