0

So i have lets say a powershell script called CallMePlease.ps1

This script will take parameters / arguments and then does some a process. How do I append the arguments to the call when I call this script from MAIN.ps1? Code I have so far:

$ScriptPath = C:\Tmp\PAL\PAL\PAL\PAL.ps1
$Log 'C:\Users\k0530196\Documents\log.csv'
$ThresholdFile 'C:\Program Files\PAL\PAL\template.xml'
$Interval 'AUTO'
$IsOutputHtml $True
$HtmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].htm'
$IsOutputXml $True
$XmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].xml'
$AllCounterStats $False
$NumberOfThreads 1
$IsLowPriority $False

$cmd = "$ScriptPath\.\PAL.ps1"

Invoke-Expression "$cmd $Log $ThresholdFile $Interval $IsOutputHtml $HtmlOutputFileName $IsOutputXml $XmlOutputFileName $AllCounterStats $NumberOfThreads"
5
  • I think you are missing some =s in there as well Commented Oct 14, 2014 at 14:53
  • Yeah, I just assumed those were typos. :) Commented Oct 14, 2014 at 14:54
  • Sorry Matt , i didnt pick up where i missed the = ... also i'm think of adding this as the first line : $ScriptPath = Split-Path $MyInvocation.InvocationName Good Idea ? Commented Oct 14, 2014 at 15:03
  • Guys i tried running my script i got the following error : Unexpected token 'C:\Shawn\pc\log.csv' in expression or statement. At C:\Shaan\PAL\PAL\Pal\ScriptReport_Create.ps1:2 char:70 + $Log 'C:\Shawn\pc\log.csv' <<<< + CategoryInfo : ParserError: (C:\Shawn\pc\log.csv:String) [], ParseException + FullyQualifiedErrorId : UnexpectedToken Commented Oct 14, 2014 at 15:21
  • That would be the missing = I think. I'll edit my answer. Commented Oct 14, 2014 at 15:23

1 Answer 1

1

In the code that you posted you are missing several =s in your assignment statements. For instance this line:

$Log 'C:\Users\k0530196\Documents\log.csv'

Should be this:

$Log = 'C:\Users\k0530196\Documents\log.csv'

You will need to do that in all the instances where you are trying to assign a value to a variable.

I would do it like this:

. $cmd $Log $ThresholdFile $Interval $IsOutputHtml $HtmlOutputFileName $IsOutputXml $XmlOutputFileName $AllCounterStats $NumberOfThreads
Sign up to request clarification or add additional context in comments.

4 Comments

hmmmm interesting but here you dont specify the powershell script im calling .. ? from my understanding that just stores the arguments that are suppose to be passed on to ps1 in Env var $cmd
$cmd is the script that you are calling right? It is in there.
yup true it is, i noticed after however now that i try the script i get the parse error regarding log ... it's weird i though it would have worked.. .
oops now i feel kinda dumb :( , let me try this out thank you EBGreen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.