Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell pass variable to ArgumentList

I have some trouble passing a variable to an ArgumentList. I want to install Teamviewer via MSI with powershell:

Start-Process 'msiexec.exe' -ArgumentList $tvparams

i want to deploy the machine on a Teamviewer-Site and pass the variable $serialnumber as the alias:

$serialnumber = (get-ciminstance -classname win32_bios -property serialnumber).serialnumber


$tvparams = '/i','ASSIGNMENTOPTIONS="--alias  $serialnumber"'

The onboarding of the machine works but instead of the actual serialnumber as an alias the machine pops up as "$serialnumber" on the Teamviewer-Site as if it is a String instead of a variable.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Im fiddling with the quotes for too long so im asking now. I feel like there must be a simple solution

>Solution :

the machine pops up as "$serialnumber" on the Teamviewer-Site as if it is a String instead of a variable.

That’s because you’re using ' single-quotes – variable expansion only works in " double-quoted strings.

You can get around it by switching to double-quotes and escaping the literal double-quotes:

$tvparams = '/i',"ASSIGNMENTOPTIONS=""--alias  $serialnumber"""

Or by using the -f string format operator:

$tvparams = '/i',$('ASSIGNMENTOPTIONS="--alias  {0}"' -f $serialnumber)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading