angusmf
Posts: 9
Joined: Wed Dec 16, 2015 5:54 pm

Set property in Powershell without literal name

With AI_MsiSetProperty, how can I use a variable instead of the name of the property literally spelled out in script? I need to arbitrarily set properties by name. This example fails when it calls AI_MsiSetProperty.

$propname = "FOO"
$propval = "FOOVAL"
AI_MsiSetProperty $propname $propval

Is there a away around this? Powershell custom actions would be pretty much pointless with this limitation.
Dan
Posts: 4529
Joined: Wed Apr 24, 2013 3:51 pm

Re: Set property in Powershell without literal name

Hello,

Please note that the AI_GetMsiProperty and AI_SetMsiProperty are powershell cmdlets that allow to set an installer property or to get the value of an installer property. So, can you please review your question?

Also note that you misspelled the AI_MsiSetProperty cmdlet. It is AI_SetMsiProperty .

Let me know if that helped, otherwise please give me more details about your specific scenario.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
angusmf
Posts: 9
Joined: Wed Dec 16, 2015 5:54 pm

Re: Set property in Powershell without literal name

Yes, it was the misspelling. Thank you!
Dan
Posts: 4529
Joined: Wed Apr 24, 2013 3:51 pm

Re: Set property in Powershell without literal name

You're welcome,

If there is anything else I can help you with, please let me know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
angusmf
Posts: 9
Joined: Wed Dec 16, 2015 5:54 pm

Re: Set property in Powershell without literal name

Bringing this back up because I'm having a related problem. Setting a property is no problem, but getting a property by a variable name turns out not to work. I'm running this powershell script from a custom action off a dialog, just to test the functionality.

This is an example of a line that returns no value:

[string] $props = "INSTALL_PROPS_PROPSTOSAVE"
$PropsToSave = AI_GetMsiProperty $props

But this does:

$PropsToSave = AI_GetMsiProperty INSTALL_PROPS_PROPSTOSAVE


Is there any way to make this work? I'm trying to load all properties from a file.

Code: Select all

function SaveProps()
{

	$filepath = AI_GetMsiProperty SETUPEXEDIR
	$filename  = AI_GetMsiProperty INSTALL_PROPS_FILE
	$file = $filepath + "\" + $filename + ".tmp"

	[string] $props = "INSTALL_PROPS_PROPSTOSAVE"
	
	$PropsToSave = AI_GetMsiProperty INSTALL_PROPS_PROPSTOSAVE
	#$PropsToSave = AI_GetMsiProperty $props

	"#Install Properties" > $file
	foreach ($prop in $PropsToSave.Split(";"))
	{

	   $val = AI_GetMsiProperty $prop
	   #if is not empty, add the property and value
			if ($val)
			{
				$line = $prop + "=" + $val
			} else {
				$line = $prop + "=" + $prop.length 
			}
			$line >> $file

	}
	
}

SaveProps
angusmf
Posts: 9
Joined: Wed Dec 16, 2015 5:54 pm

Re: Set property in Powershell without literal name

Still need an answer to this.
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Set property in Powershell without literal name

Hello,

First of all we apologize for such a delayed reply. It seems your post was somehow overlooked.

Indeed, unfortunately we don't have support to use a variable to specify the property name when getting a property value (i.e. using "AI_GetMsiProperty" syntax). This can done only when setting property values, i.e. when using the "AI_SetMsiProperty" syntax. Currently this is a limitation of our PowerShell custom actions support. I've added a task in our todo list so we can investigate and try to enhance our PowerShell custom action support so that you can use a variable to specify the property name when using the "AI_GetMsiProperty" syntax. Thank you for your suggestion. We will notify you when this will have a resolution.

Until then, I'm afraid there is no workaround. Thank you for your understanding.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Set property in Powershell without literal name

You're always welcome.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
dlenis
Posts: 40
Joined: Wed Nov 02, 2016 2:37 pm

Re: Set property in Powershell without literal name

Daniel,
I know this thread is old but when will a fix be issued for reading a property using a variable in PowerShell? This issue limits what we can do in PowerShell.

Thank you,

Diego
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Set property in Powershell without literal name

Hello Diego,

This improvement is still on a pending state on our todo list. I'm afraid I cannot give you any ETA for now. I'll try to get a higher priority for this and as soon as we will have updates we will let you know.

Thank you for your understanding.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”