Hello Stack Community :)
I have a simple goal. I'd like to start some PowerShell Script from an another Powershell Script, but there are 3 conditions:
- I have to pass credentials (the execution connects to a database that has specific user)
- It has to take some Parameters
- I'd like to pass the output into a variable
There is a similar question Link. But the answer is to use files as a way to communicate between 2 PS Scripts. I just would like to avoid access conflicts. @Update: The Main Script is going to start few other scripts. so the solution with files can be tricky, if the execution will be performed from multiple user at the same time.
Script1.ps1 is the script that should have string as an output. (Just to be clear, it's a fictive script, the real one has 150 Rows, so I just wanted to make an example)
param(
[String]$DeviceName
)
#Some code that needs special credentials
$a = "Device is: " + $DeviceName
$a
ExecuteScripts.ps1 should invoke that one with those 3 conditions mentioned above
I tried multiple solutions. This one for examplte:
$arguments = "C:\..\script1.ps1" + " -ClientName" + $DeviceName
$output = Start-Process powershell -ArgumentList $arguments -Credential $credentials
$output
I don't get any output from that and I can't just call the script with
&C:\..\script1.ps1 -ClientName PCPC
Because I can't pass -Credential parameter to it..
Thank you in Advance!