Script Monitor with Param()

Script Monitor with Param()

I am trying to create a monitor to track when a cert is going to expire.  Works great when using it outside OpManager but when I try and use it as a script monitor I get the following error:

E:\Program Files\ManageEngine\OpManager\bin\temp\OpManager_Script_3901_1681840754938.ps1 : A positional parameter 
cannot be found that accepts argument '2'.
At line:1 char:1
+ .\OpManager_Script_3901_1681840754938.ps1 -ComputerName MyServer ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [OpManager_Script_3901_1681840754938.ps1], ParameterBindingExceptio 
   n
    + FullyQualifiedErrorId : PositionalParameterNotFound,OpManager_Script_3901_1681840754938.ps1


I am calling the script in the monitor with the following command:
cmd /c powershell.exe -ExecutionPolicy RemoteSigned .\${FileName}.ps1 -ComputerName "${DeviceName}" -UserName ${UserName} -PWD "${Password}"

Note: I defined the Parameters because passwords can contain spaces which seems to confuse OpManager if I just tried to use $args
  1. Param(
  2.     [Parameter()]$ComputerName,
  3.     [Parameter()]$UserName,
  4.     [Parameter()]$PWD
  5. )


  6. $Password = ConvertTo-SecureString $PWD -AsPlainText -Force
  7. $Credential = New-Object System.Management.Automation.PsCredential($userName, $Password)


  8. $certs = Invoke-Command -Credential $Credential -ComputerName $ComputerName -ScriptBlock {Get-ChildItem Cert:\LocalMachine\My | Where { $_.Extensions.format(1) -match "Machine"}}
  9. $CertStats = $certs | Select Issuer, Subject, Thumbprint, @{N='StartDate';E={$_.NotBefore}},
  10.    @{N='EndDate';E={$_.NotAfter}},
  11.    @{N='DaysRemaining';E={($_.NotAfter - (Get-Date)).Days}}

  12. Write-Host "Data:"
  13. Write-Host "DaysRemaining `t" $CertStats.DaysRemaining

              New to ADManager Plus?

                New to ADSelfService Plus?