0

Is there a way to be able to add variables in this command?

Set-NAVServerConfiguration -ServerInstance $ServiceName -KeyName "DestinationAppsForMigration" -KeyValue '[{"appId":"12345-6789", "name":"Some Name", "publisher": "Some Publisher" }]'

What I would like to have would be something like this:

Set-NAVServerConfiguration -ServerInstance $ServiceName -KeyName "DestinationAppsForMigration" -KeyValue '[{"appId":$TableMigrationExtID, "name":$TableMigrationExtName, "publisher": $TableMigrationExtPublisher }]'

With the $TableMigrationExtID, $TableMigrationExtName and $TableMigrationExtPublisher containing the values. If I try to run it shows this error Error

1
  • just switch ' and " Commented Sep 18, 2020 at 12:32

2 Answers 2

1

According to About Quoting, you must surround your string with outer double quotes in order for inner variables to be substituted with their values. Given that you need to retain inner double quotes as well, you will have to escape them with a backtick or another double quote.

Using Double Quote Escape:

Set-NAVServerConfiguration -ServerInstance $ServiceName -KeyName "DestinationAppsForMigration" -KeyValue "[{""appId"":$TableMigrationExtID, ""name"":$TableMigrationExtName, ""publisher"": $TableMigrationExtPublisher }]"

Using Backtick Escape:

Set-NAVServerConfiguration -ServerInstance $ServiceName -KeyName "DestinationAppsForMigration" -KeyValue "[{`"appId`":$TableMigrationExtID, `"name`":$TableMigrationExtName, `"publisher`": $TableMigrationExtPublisher }]"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Wasn't getting the result but then I noticed it wasn't passing properly as the error message showed. Add to add double " again on the variables. So this worked, thanks! Set-NAVServerConfiguration -ServerInstance $ServiceName -KeyName "DestinationAppsForMigration" -KeyValue "[{""appId"":$TableMigrationExtID, ""name"":$TableMigrationExtName, ""publisher"": $TableMigrationExtPublisher }]"
0

It is possible. A quick and dirty answer

Set-NAVServerConfiguration -ServerInstance $ServiceName -KeyName "DestinationAppsForMigration" -KeyValue '[{"appId":' + $TableMigrationExtID + ', "name":' + $TableMigrationExtName + ', "publisher":' + $TableMigrationExtPublisher + ' }]'

You basicly plus the string together with 'something' + $variable + 'something more'

1 Comment

I got this error trying this solution, Set-NAVServerConfiguration : A positional parameter cannot be found that accepts argument '+'. Thanks for replying!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.