How can I pass variable colors to be printed from a python script by calling a powershell function.
function check($color){
Write-Host "I have a $color shirt"
}
import subprocess
color = "blue"
subprocess.call(["powershell.exe", '-Command', '&{. "./colortest.ps1"; & check(color)}'])
Above code results in below error
color : The term 'color' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:27
+ &{. "./colortest.ps1"; & check(color)}
+ ~~~
+ CategoryInfo : ObjectNotFound: (color:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
If I directly insert the actual color as a constant parameter, then I get the desired result but replacing it with a variable fails.
subprocess.call(["powershell.exe", '-Command', '&{. "./colortest.ps1"; & check("blue")}'])
Result
I have a blue shirt