Oschestrator Powershell script problem

Dear expert

Below script code works fine i powershell, Im trying to add this in the orchestrator(A SCCM add-in) I got this error:

Cannot bind parameter 'Date' to the target. Exception setting "Date": "Object reference not set to an instance of an object."
Seems it complain this: $dateFilter = get-date $dateFilter -format yyyy-MM-dd, I kinda knew that SSCM Orchestrator use the old PS version, now I dont know what to do to fix this problem. Well the function Im after is: when you run the script till well first get running date with format yyyy-MM-dd and then use that line into a sql query.

Anyone know the solution for it? Thanks.

$SQLServer = "System"
$SQLDBName = "Prod"
$months = 2
$dateFilter = get-date $dateFilter -format yyyy-MM-dd

function f_sqlquery ($dateFilter) {

      $SqlQuery = "
      DECLARE
            @ReminderMonth date = '$dateFilter';
      DECLARE
            @P1 int = (      SELECT      COUNT(*)
                              FROM        Invoice.Reminder R
                              WHERE       R.DatetimeSentToReceiver >= @ReminderMonth
                              AND R.DatetimeSentToReceiver < DATEADD(MONTH, 1, @ReminderMonth)
                              AND R.ReminderNumber = 1 ),
            @P2 int = (      SELECT      COUNT(*)
                              FROM        Invoice.Reminder R
                              WHERE       R.DatetimeSentToReceiver >= @ReminderMonth
                              AND R.DatetimeSentToReceiver < DATEADD(MONTH, 1, @ReminderMonth)
                              AND R.ReminderNumber = 2 ),
            @P3 int = (      SELECT      COUNT(*)
                              FROM        Invoice.Reminder R
                              WHERE       R.DatetimeSentToReceiver >= @ReminderMonth
                              AND R.DatetimeSentToReceiver < DATEADD(MONTH, 1, @ReminderMonth)
                              AND R.ReminderNumber = 3 );
      
      select CONVERT(varchar(7),@ReminderMonth,120) AS 'Month' , @P1 AS 'Reminder 1', @P2 AS 'Reminder 2', @p3 AS 'Reminder 3', SUM(@P1+@P2+@P3) AS 'Reminder total'

      "
      
      
      return $DataSet.Tables[0].Rows
}


$sqlArr = @()

if ($months -gt 1) {
      $months--
      0..$months | % {
            $dateQuery = ( get-date (get-date $dateFilter).AddMonths( $_ ) )
            if ( (get-date $dateQuery) -le (get-date) ) {
                  $sqlArr += f_sqlquery $dateQuery $SQLDBName
            }
      }
} else {
      $sqlArr += f_sqlquery $dateFilter $SQLDBName
}
LVL 1
WeTiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
That's got nothing to do with the PowerShell version; they way you're setting the variable is incorrect. You need to remove the "$dateFilter" (which is an empty variable at this point) from the line it complains about:
$dateFilter = Get-Date -Format yyyy-MM-dd

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeTiAuthor Commented:
right
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.