How to use the "at-run" parameters as parameters within the function. Right now my code is returning all data/value regardless of what is enter for the "at-run" parameters.
For example, I will like to match the $Server_Name from the "at-run" parameters with the foreach loop, so that only data with the matching $Server_Name is return.
function StartServer{
Param (
[Parameter (Mandatory=$true)] [STRING] $Region,
[Parameter (Mandatory=$true)] [STRING] $Env,
#[STRING] $Env,
[Parameter (Mandatory=$true)] [STRING] $ScriptName, #$ScriptName
[Parameter (Mandatory=$true)] [STRING] $Server_Name
#[STRING] $Server,
#[STRING] $Services
)
#Write-Output ("Region: "+ $Region + " Env: " + $Env + " ScriptName: " + $ScriptName + " Server_Name: " + $Server)
#$startDate = Get-Date;
$Sourcefile = "C:\Users\ Scripts\CLEAN10182019.csv"
$StartProperties = (Import-Csv $Sourcefile)
$Sorted = $StartProperties |select Server_Name,Service_Name, Start_Order, Start_Flag, Start_Wait | Sort-Object -Property Server_Name, {[int]$_.Start_Order}|Format-Table
#$Sorted
foreach($line in $StartProperties)
{
$Server_Name = [string]$line.'Server_Name'
$Service_Name = [string]$line.'Service_Name'
$Start_Order = [string]$line.'Start_Order'
$Start_Wait= [string]$line.'Start_Wait'
$file = #"Matches? " + $Server_Name
"Start " + $Service_Name + " " + " Timeout " + $Start_Wait
Write-Output $file
}
}
StartServer