I have a powershell script file which is as follows
param(
[parameter(Mandatory = $true)]
[string] $db_server,
[parameter (Mandatory = $true)]
[string[]] $db_server_list
)
write-output "My DB server is $db_server"
foreach ($list in $db_server_list)
{
write-output $list
}
Let us assume the file is saved as script1.ps1
On my development laptop, I can run this from visual studio code without any issues.
.\script1.ps1 -db_Server 'my_db_server,999' -db_server_list ("server1,5694","server2,7788")
It runs fine, the value of db_Server is as specified that is my_db_server,999 and i am able to loop through the db_Server_list without loosing the comma which is the port number.
I am calling the file from an external orchestration program, and to do so. I need to run
powershell.exe .\script1.ps1 -db_Server 'my_db_server,999' -db_server_list ("server1,5694","server2,7788")
And all of a sudden i get errors.
Cannot process argument transformation on parameter 'db_server'. cannott convert value to type System.string. I do not want db_server to be an array even though it has a comma, I need it back as a single string as I used this for a connection string, and if the value after the comma is stripped off, it will break my script.
Please note that this only happens when i call powershell.exe scriptfile.ps1. Running from VS code doesnt result in such errors.
Thanks all.
I have ran it again, its thesame issue.
The reason why I need to add powershell.exe is because I am calling the script from an ansible playbook.