Andrey.Burda
Posts: 23
Joined: Tue Dec 14, 2021 12:06 pm

Dynamic property name for AI_GetMsiProperty

Tue Jan 25, 2022 8:58 am

Hello,

I want to pass in a dynamic value for AI_GetMsiProperty inside the Power Shell inline script (execution time is set to Immediately) but it does not work.

General aim is to get a folder path inside the loop by calculating a property name from "Files and Folders".

For instance I haver a folder "TestApi" and "TestApi1", the identifiers generated by AI are: TestApi_Dir and TestApi1_Dir.
I have a comma separated string with a list of folder names in custom property - MIGRATION_SERVICES. It value is "TestApi,TestApi1".

In Power Shell script I do the following:

Code: Select all

$migrationServices = AI_GetMsiProperty MIGRATION_SERVICES

$migrationServices.Split(",") | ForEach-Object {
  $dirName = $_ + "_Dir"
  $Path = AI_GetMsiProperty $dirName
  if ($Path -ne '') {
  }
}
exit 0
$dirName is set to: TestApi_Dir and TestApi1_Dir.
The problem is that $Path is always empty, but this line will return a correct path: $Path = AI_GetMsiProperty TestApi_Dir

I wonder what I missed?

Regards,
Andrey

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Wed Jan 26, 2022 5:00 pm

Hello Andrey,

Please note that the AI_GetMsiProperty cmdlet cand only be used with installer properties.

In your case, $dirName is a variable, not an installer property.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Andrey.Burda
Posts: 23
Joined: Tue Dec 14, 2021 12:06 pm

Re: Dynamic property name for AI_GetMsiProperty

Thu Jan 27, 2022 3:44 pm

Hi Catalin,

Thanks for the reply.
Is there any way to receive AI properties in Powershell script a bit more dynamically, for instance by string name ?

Regards,
Andrey

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Mon Jan 31, 2022 9:42 am

Hello Andrey,

You can first retrieve the property into a variable and then pass the value to another variable, something like this:

Code: Select all

$var = AI_GetMsiProperty SOME_PROPERTY
$var2 = $var

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Andrey.Burda
Posts: 23
Joined: Tue Dec 14, 2021 12:06 pm

Re: Dynamic property name for AI_GetMsiProperty

Tue Feb 01, 2022 11:21 am

Hi Catalin,

Unfortunately, I have a string name of the property and I want to get it value that set in AI Properties.
Looks like PowerShell inline script is not my option at all.

Regards,
Andrey

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Tue Feb 01, 2022 2:48 pm

Hello Andrey,

Perhaps I am misunderstanding something here.

So, you have the name of the property stored in a variable, e.g.:

$var = "MY_PROP"

and then you want to retrieve the value of "MY_PROP" into another variable, e.g.:

Code: Select all

$var2 = AI_GetMsiProperty $var
where $var would eventually be replaced by "MY_PROP" and then $var2 would have the value of "MY_PROP"?

Is this what you are trying to achieve? If this is the case, then I'm afraid this might not be possible with the AI_GetMsiProperty cmdlet.

However, there might be another way, through the Get-Property cmdlet (which we recently added), e.g.:

Code: Select all

$var = "MY_PROP"

$var2 = Get-Property -name $var
Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Andrey.Burda
Posts: 23
Joined: Tue Dec 14, 2021 12:06 pm

Re: Dynamic property name for AI_GetMsiProperty

Tue Feb 01, 2022 3:34 pm

Hi Catalin,

Seems that "Get-Property cmdlet" is what I need.
Thanks a lot!

Regards,
Andrey

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Tue Feb 01, 2022 3:50 pm

You are always welcome, Andrey!

Glad I could help.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

MGS
Posts: 82
Joined: Tue Oct 04, 2022 9:52 am

Re: Dynamic property name for AI_GetMsiProperty

Thu Dec 01, 2022 3:55 pm

I just found this thread after spending hours trying to get my code to work, only to find out that the culprit is the AI_GetMsiProperty command. I tried to use the AI_GetMsiProperty with a dynamic value. Now here seems to be the solution, using the Get-Property cmdlet, but funny enough it does not work for me.

1) Why does this Powershell code work:

Code: Select all

#Requires -version 3
Param()

Function DataSourceUseRegistry() {
	[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')

	$var3 = AI_GetMsiProperty "DATABASE_PROP_REGISTRY"
	[System.Windows.Forms.MessageBox]::Show("testme: $var3")

	$var = "DATABASE_PROP_REGISTRY"
	$var2 = Get-Property -name $var
	[System.Windows.Forms.MessageBox]::Show("testme: $var2")
}

DataSourceUseRegistry
But this does not:

Code: Select all

#Requires -version 3
Param()

Function DataSourceUseRegistry() {
	[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
	
	$var = "DATABASE_PROP_REGISTRY"
	$var2 = Get-Property -name $var
	[System.Windows.Forms.MessageBox]::Show("testme: $var2")
}

DataSourceUseRegistry
Hint: I assigned the DATABASE_PROP_REGISTRY to a value inside the Properties View.

2) I could not find any documentation on the Get-Property cmdlet. Is there any documentation available? Also, is there a Set-Property cmdlet available too (that basically works like AI_SetMsiProperty but allows for a dynamic property parameter)? If yes, what are the parameters?

All the best,
Johannes

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Tue Dec 06, 2022 4:54 pm

Hello Johannes,

I've done some tests regarding the get-property cmdlet and indeed something seems to be off with it.

I have opened a ticket so our dev team can further investigate this.

I will followup here when I will have more details.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

MGS
Posts: 82
Joined: Tue Oct 04, 2022 9:52 am

Re: Dynamic property name for AI_GetMsiProperty

Mon Dec 12, 2022 10:00 am

Hi Catalin,

Thank you very much for your testing and opening the ticket!

1. What is the ETA on this?
2. Do you have any information regarding a similar set-property method? Is that available too? If yes, what are its parameters?

Best regards,
Johannes

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Mon Dec 12, 2022 2:10 pm

Hello Johannes,

I'm afraid I can not give an ETA for this.

In what regards Set-Property, yes that is available too. This is, as Get-Property, more like an alias for "AI_SetMsiProperty".

With that being said, it would work like this:

Code: Select all

Set-Property PROPERTY_NAME "Property_value"
Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Thu Feb 23, 2023 9:24 am

Hello,

As a followup to this, in order to get this working, we have to do a little hack, as it follows:

Code: Select all

$var = "TEST_PROP"
# Get-Property TEST_PROP
$anotherVar = Get-Property name $var
Basically, we add a comment as the above and then we should be able to dynamically retrieve the value of a property.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

MGS
Posts: 82
Joined: Tue Oct 04, 2022 9:52 am

Re: Dynamic property name for AI_GetMsiProperty

Thu Feb 23, 2023 10:51 am

Hi Catalin,

Thanks for the follow up!

I had already figured out this behavior myself when I first posted in this thread, as you can see above, where I ask why the first code snippet works and the second one doesn't.

Still, I hope for a solution to this problem in the future, as manually entering each property name up front within the code defeats the purpose of using dynamic properties in the first place. The ability to use dynamic properties without defining them in advance would give us much more freedom. For example, it would be possible to assign 50 dynamic properties without us having to know their name and number.

Have a great day,
Johannes

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Dynamic property name for AI_GetMsiProperty

Thu Feb 23, 2023 1:44 pm

You are always welcome, Johannes!

Thank you for your input.

I have forwarded it to our dev team.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”