VMware Cloud Community
forsco
Contributor
Contributor
Jump to solution

invoke-vmscript not allowing variables

This is what I have and it just hangs. I show that the application is started but it does not do anything, the agent does not get installed. Does anyone have any ideas I thought I followed the example well.
Note: I can install this running it on the VM's fine with the silent installer.

 

 

 

 

$src2 = @'&"$env:C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe" "$env:/s /v "/qb INSTALL_VDISPLAY=1 VDM_VC_MANAGED_AGENT=1 ADDLOCAL=Core,USB,VmwVaudio,VmwVidd,ScannerRedirection,PrintRedir,RTAV,ClientDriveRedirection,V4V,GEOREDIR,PerfTracker""'
Invoke-VMScript -ScriptType powershell -ScriptText $scr2 -VM $TeplateVMName -GuestCredential $Cred

 

 


I have also attempted this way

 

 

$code1 = @'
C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe /s /v '"/qb INSTALL_VDISPLAY=1 VDM_VC_MANAGED_AGENT=1 ADDLOCAL=Core,USB,VmwVaudio,VmwVidd,ScannerRedirection,PrintRedir,RTAV,ClientDriveRedirection,V4V,GEOREDIR,PerfTracker"'
'@
Invoke-VMScript -scripttype Powershell -scripttext $code1 -VM $TeplateVMName -GuestCredential $Cred ​

 

 



 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you try with just

$code = @'
C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe /s /v "/qn INSTALL_VDISPLAY=1 VDM_VC_MANAGED_AGENT=1 ADDLOCAL=Core,USB,VmwVaudio,VmwVidd,ScannerRedirection,PrintRedir,RTAV,ClientDriveRedirection,V4V,GEOREDIR,PerfTracker"
'@

Invoke-VMScript -ScriptType Bat -ScriptText $code -VM $TeplateVMName -GuestCredential $Cred

That seems to work for me.

Two changes:
- use single quotes on the here-string
- use Scripttype Bat, since this is just a regular EXE, no PS required 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Your 1st snippet has an incorrect here-string, and the variable name used in the Invoke-VMSCript is not correct.

That should be

$src2 = @'
&"$env:C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe" "$env:/s /v "/qb INSTALL_VDISPLAY=1 VDM_VC_MANAGED_AGENT=1 ADDLOCAL=Core,USB,VmwVaudio,VmwVidd,ScannerRedirection,PrintRedir,RTAV,ClientDriveRedirection,V4V,GEOREDIR,PerfTracker""
'@
Invoke-VMScript -ScriptType powershell -ScriptText $src2 -VM $TeplateVMName -GuestCredential $Cred

The command runs under the account that the VMware Tools are running under.
Is that account allowed to do installations?
Do you hit the UAC prompt?
Because then the command will time out.


 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
forsco
Contributor
Contributor
Jump to solution

Running into this with a copy and paste of your edits

 

 

 At line:1 char:26
+ & {&"$env:C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe" "$env:/s /v "/qb INSTALL_VDISPLAY=1 VDM_VC_MA ...
+ ~~~~~
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to

 

 


The guest creds I am using are a local admins account and when I log into the machine and run the silent installer I do not get prompted with the UAC.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like your copy/paste has an issue.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
forsco
Contributor
Contributor
Jump to solution

it looks like the problem is the second part it does not like after the second $env.

"$env:/s /v "/qb INSTALL_VDISPLAY=1 VDM_VC_MA .

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

What is the actual command you want to run inside the Guest OS?
I'm not sure I understand the use of the $env variable.
In a here-string with single quotes there is no variable substitution, so the $env will be passed to the Guest OS


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Tags (1)
Reply
0 Kudos
forsco
Contributor
Contributor
Jump to solution

This is the command that I use locally when doing it
 

 

C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe /s /v "/qn INSTALL_VDISPLAY=1 VDM_VC_MANAGED_AGENT=1 ADDLOCAL=Core,USB,VmwVaudio,VmwVidd,ScannerRedirection,PrintRedir,RTAV,ClientDriveRedirection,V4V,GEOREDIR,PerfTracker"

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And what is the idea behind that $env in the code?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
forsco
Contributor
Contributor
Jump to solution

honestly I was just trying it since it didn't work the other way as well. I need the quotes in the command I think those are messing it up. I also just tried putting it in the invoke-vmscript in the -scripttest with {} around it and it kept not sending the whole thing.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you try with just

$code = @'
C:\VMware-Horizon-Agent-x86_64-2111.1-8.4.0-19066669.exe /s /v "/qn INSTALL_VDISPLAY=1 VDM_VC_MANAGED_AGENT=1 ADDLOCAL=Core,USB,VmwVaudio,VmwVidd,ScannerRedirection,PrintRedir,RTAV,ClientDriveRedirection,V4V,GEOREDIR,PerfTracker"
'@

Invoke-VMScript -ScriptType Bat -ScriptText $code -VM $TeplateVMName -GuestCredential $Cred

That seems to work for me.

Two changes:
- use single quotes on the here-string
- use Scripttype Bat, since this is just a regular EXE, no PS required 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
forsco
Contributor
Contributor
Jump to solution

🎉

Perfect, That worked, thank you. I was about to give up and write the one-liner and push the script to the guest and run it with the invoke-vmscript!


Reply
0 Kudos