0

I have 2 scripts: Script #1 is calling to script #2 with several params But i wasn't able to get the params in script #2 Maybe you can advise please

Script #1:

$Version = "227"
$Type = "regular"

C:\GetParamsScript.ps1 -Version_To_Compare $Version -Type_Of_Report  $Type 

Script #2:

$Version_To_Compare
$Type_Of_Report

write-host "Version_To_Compare $Version_To_Compare"
write-host "Type_Of_Report $Type_Of_Report"
1
  • 1
    Script #2 is missing a param(...) block with parameter declarations - see the conceptual about_Functions help topic Commented Aug 8, 2022 at 14:31

1 Answer 1

2

I'm not sure if the script you've posted here is the whole thing, but you should use param blocks to pass data into your script/function.

So script #2 would look have something like this;

param (
    [Parameter(Mandatory=$true)]
    [string]$Version_To_Compare,
    [string]$Type_Of_Report
    
)

You would then use the parameter variables the same way you're using them now.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that Parameter() attributes apply only to the one parameter immediately following it, so $Type_Of_Report is an optional parameter in your example.

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.