HiI am new to powershell, and am struggling a bit with the passing of an array as a variable. Firstly, I have a function which will return a set of server names based on and variable for the environment. However, when I try to pass the output from the function to another script, it only returns data for the first value (I have set up my test for 3 servers to be returned). I must be passing the variable incorrectly, or scoping it incorrectly, but I am a bit stuck now. Can anyone tell me where I am going wrong, please?-----------------------------------------------------------------------------------------Function:Function GetComputerList{ Param( [string]$Environment) $comparray = @() $query = "SELECT ServerNameFROM Server SINNER JOIN dbo.Environment EON S.EnvironmentID = E.EnvironmentIDWHERE E.EnvironmentName = '$Environment'" $connection = new-object system.data.sqlclient.sqlconnection( "Data Source=localhost;Initial Catalog=Test;Integrated Security=SSPI;”) $adapter = new-object system.data.sqlclient.sqldataadapter ($query, $connection) $table = new-object system.data.datatable $adapter.Fill($table) | out-null $compArray = @($table | select -ExpandProperty ServerName) return ($compArray)}----------------------------------------------------------------------------Script 1:. \Powershell\GetComputerList.ps1set-location C:\Powershell#Write-Host "Calling CheckJavaProcesses"$ComputerArray = @()$ComputerArray = GetComputerList 'Prod'Write-host $ComputerArray#check AL_engine processes$Command = ".\CheckJavaProcesses.ps1 '$ComputerArray'"Invoke-Expression $Command--------------------------------------------------------------Script 2:param([string[]] $ComputerArray)$date = (get-date).tostring("yyyyMMddhhmm")$logfile = "C:\Powershell\Logs\PRD_CheckProcesses_$date.log"Write-Host $ComputerArray# ProcessesForEach ($i in $ComputerArray ){$i >> $logfile; get-process -computername $i -name java* >> $logfile}Notepad $logfileThanks for any help in advance :-)
↧