0
Hello
A Powershell script has the following code:
function GetPerfis
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string]$StartDate,
        [Parameter(Mandatory)]
        [string]$EndDate
    )
     $cmd = New-Object System.Data.SqlClient.SqlCommand
    $cmd.Connection = $conn
    $cmd.Transaction = $transaction
    LogWrite  "GetProfiles startDate: $startDate and endDate: $endDate"
    ....
}
$startDate = $args[0]
$endDate = $args[1]
LogWrite  "startDate: $startDate and endDate: $endDate"
$profiles = GetPerfis -StartDate $startDate -EndDate $endDate
Output in log:
startDate: 2014-01-01 and endDate: 2015-01-01
GetProfiles startDate: 2014-01-01 and endDate: 2015-01-01
Give me the following mistake:
System.Management.Automation.RuntimeException: You cannot call a method on a 
null-valued expression.
Any idea the reason for the mistake?
In this solution appears me the error: "The assignment Expression is not Valid. The input to an assignment Operator must be an Object that is Able to Accept assignments, such as a variable or a Property." Do you have any idea why?
– user2989745
Yes, the param() is to place before the remaining ps1 instructions. [https://www.red-gate.com/simple-talk/sysadmin/powershell/how-to-use-parameters-in-powershell/]
– Canoas
I already put at the beginning of the script but I still have the same error. It gives error in assigning the default value in the first parameter...
– user2989745