just getting started writing scripts

Welcome Forums General PowerShell Q&A just getting started writing scripts

This topic contains 1 reply, has 2 voices, and was last updated by

10 months ago.

  • Author
  • #99490

    Points: 0
    Rank: Member

    I'm just getting started, and trying to pass command-line parameters to a PowerShell script.

    After checking the documentation, I thought something like this would work:

    Param ( String[] $PackageId, String[] $NOGDOC )

    However, after attempting it, the error messages seem to suggest that this method is for passing parameters to internal functions, rather than from the (external) command line.

    Are the command-line arguments available in a pre-defined variable?

    Thanks in advance for any help you can provide.

  • #99492

    Points: 1
    Rank: Member

    It's a syntax issue.

    Example: (test.ps1)

        [string] $Param1,
        [int] $Param2,
        [string[]] $Param3
    Write-Host "$Param1 : $Param2"
    Write-Host "Array count: $($Param3.count)"
    $Param3 | ForEach-Object {Write-Host "ArrayValue: $_"}


    .\test.ps1 -Param1 "A String" -Param2 7 -Param3 "Value1", "Value2", "Value3"


    A String : 7
    Array count: 3
    ArrayValue: Value1
    ArrayValue: Value2
    ArrayValue: Value3

The topic ‘just getting started writing scripts’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort