Mauro Cazabonnet
asked on
Powershell pass array of objects to another script
Hi,
Trying to pass an object array to another script as follows
script I'm calling script1.ps1
---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
main script calling script above
the array param is not outputting to the file on the script script.ps1
Any help much appreciated....
Trying to pass an object array to another script as follows
script I'm calling script1.ps1
param(
[Parameter(ValueFromPipeline = $true)]
[object[]]$test,
[string]$batch
)
$host.ui.RawUI.WindowTitle = "Processing batch $batch "
$test | Out-File C:\work\test2.txt -Append
start-sleep -seconds 5
exit
--------------------------main script calling script above
function Invoke-Command() {
param ( [string]$program = $(throw "Please specify a program" ),
[string]$argumentString = "",
[switch]$waitForExit )
$psi = new-object "Diagnostics.ProcessStartInfo"
$psi.FileName = $program
$psi.Arguments = $argumentString
$proc = [Diagnostics.Process]::Start($psi)
if ( $waitForExit ) {
$proc.WaitForExit();
}
}
csv file --> test.csvname,column1,column2,column3,column4
test,a,b,c,d
test1,e,f,g,h
test2,i,j,k,l
$importedcsv = import-csv .\test.csv
$batch = 1
Invoke-Command -program "powershell.exe" -argumentString "C:\work\script1.ps1 @($importedcsv) $batch" -waitForExit
the array param is not outputting to the file on the script script.ps1
Any help much appreciated....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's doing that right inside the main Powershell console. Try the scripts I posted above, and you'll see the csv from script1.ps1 in yellow.
ASKER
This should work yes?
$hvds = import-csv c:\work\pno-prod-combox35-12-05-16.csv
$batch = 1
Start-Process Powershell -ArgumentList "&C:\work\APATBuildEngine-Work.ps1 $batch $hvds"
Again: why are you complicating things by calling an external process, instead of starting the the Powershell script directly from the current session?
And note that your batch and array arguments are in a different order than in your sample script, and they're unnamed. Best practice in Powershell is to use named arguments.
And note that your batch and array arguments are in a different order than in your sample script, and they're unnamed. Best practice in Powershell is to use named arguments.
$hvds = import-csv c:\work\pno-prod-combox35-12-05-16.csv
$batch = 1
& 'C:\work\APATBuildEngine-Work.ps1' $batch $hvds
ASKER
I have a list that I then break down into batches and send to the powershell script
ASKER
Your right why over complicate
Thanks again.....
Thanks again.....
ASKER
How do I get it to spawn a command shell showing what it's doing...