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
- Param(
- [Parameter()]$ComputerName,
- [Parameter()]$UserName,
- [Parameter()]$PWD
- )
- $Password = ConvertTo-SecureString $PWD -AsPlainText -Force
- $Credential = New-Object System.Management.Automation.PsCredential($userName, $Password)
- $certs = Invoke-Command -Credential $Credential -ComputerName $ComputerName -ScriptBlock {Get-ChildItem Cert:\LocalMachine\My | Where { $_.Extensions.format(1) -match "Machine"}}
- $CertStats = $certs | Select Issuer, Subject, Thumbprint, @{N='StartDate';E={$_.NotBefore}},
- @{N='EndDate';E={$_.NotAfter}},
- @{N='DaysRemaining';E={($_.NotAfter - (Get-Date)).Days}}
- Write-Host "Data:"
- Write-Host "DaysRemaining `t" $CertStats.DaysRemaining