Good afternoon,
Is it possible to import Custom variables into a Hub Business environment using PowerShell?
Kind regards,
Ron Bouwmeester
Recommended Answer
Hello,
It is possible to import custom variables into a Hub Business environment using PowerShell, though the current solution is a workaround. You can use the Import-RDMCustomVariable cmdlet, which accepts a JSON file as input.
Here is an example of the JSON file format (custom_variables.json):
[
{
"Name": "CV1",
"Value": "Some value",
"Description": "my custom variable 1"
},
{
"Name": "SomePort",
"Value": "5432",
"Description": "Some port"
}
]
Import command:
Import-RDMCustomVariable -FilePath "C:\path\to\custom_variables.json" -ImportAction ReplaceList -VariableScope DataSource
The ImportAction parameter controls how duplicates are handled:
The VariableScope parameter controls where the variables are stored:
Please note that this is a workaround, as dedicated cmdlets for managing custom variables at the vault level are not yet available. A ticket has been logged to add proper cmdlet support for this scenario, and it will be addressed in a future release.
Do not hesitate to reach out if you have any further questions.
Best regards,
Maxime
Hello,
It is possible to import custom variables into a Hub Business environment using PowerShell, though the current solution is a workaround. You can use the Import-RDMCustomVariable cmdlet, which accepts a JSON file as input.
Here is an example of the JSON file format (custom_variables.json):
[
{
"Name": "CV1",
"Value": "Some value",
"Description": "my custom variable 1"
},
{
"Name": "SomePort",
"Value": "5432",
"Description": "Some port"
}
]
Import command:
Import-RDMCustomVariable -FilePath "C:\path\to\custom_variables.json" -ImportAction ReplaceList -VariableScope DataSource
The ImportAction parameter controls how duplicates are handled:
The VariableScope parameter controls where the variables are stored:
Please note that this is a workaround, as dedicated cmdlets for managing custom variables at the vault level are not yet available. A ticket has been logged to add proper cmdlet support for this scenario, and it will be addressed in a future release.
Do not hesitate to reach out if you have any further questions.
Best regards,
Maxime
Hello Maxime,
Thank you for your reply.
I have created the following script:
$ds = Get-RDMDataSource -Name "Devolutions Hub Business"
Set-RDMCurrentDataSource $ds
$repository = Get-RDMRepository -Name "<VaultName>" ;Set-RDMCurrentRepository $repository
Import-RDMCustomVariable -FilePath "<FilePath>\config.json" -ImportAction AddAndUpdate -VariableScope Vault
But when I execute the import startement I get the following error:
Import-RDMCustomVariable: The file format (.json) is not supported.
Can you give some advice?
In advance thank you for your reply.
Kind regards,
Ron Bouwmeester
Hello Ron,
Before investigating further, could you run the following command to verify that your file is valid JSON?
Test-Json -Path "<FilePath>\config.json"
If it returns False, the file content is malformed and will need to be fixed before importing.
Best regards,
Maxime
Hello Maxime,
Thank you very much for your reply.
Test-Json: Cannot parse the JSON.
Th content of the json file is:
{
"Name": "CV1",
"Value": "Some value",
"Description": "my custom variable 1"
},
{
"Name": "SomePort",
"Value": "5432",
"Description": "Some port"
}
Kind regards,
Ron Bouwmeester
Hello Ron,
The issue is that your JSON file is missing the surrounding array brackets [ and ]. The file should look like this:
[
{
"Name": "CV1",
"Value": "Some value",
"Description": "my custom variable 1"
},
{
"Name": "SomePort",
"Value": "5432",
"Description": "Some port"
}
]
Once corrected, Test-Json should return True and the import will work.
Best regards,
Maxime
Hello Maxime,
Thank you for your advice. It works perfect now.
Thank you for the support.
Kind regards,
Ron Bouwmeester
Hello Ron,
You are welcome! Please reach out to us if you need anything else.
Best regards,
Maxime