This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to set Parameters in Scheduled Tasks wtih Powershell

Hi,

how can i set a Parameter for a Scheduled Task in ARS 6.5 with Powershell?

I added the parameters on the scheduled Task.

In the SDK is only a VBS HowTo (Topic "Specifying Parameters for Scheduled Tasks").

I tried it on different ways in Powershell:
---
$Task = Get-QADObject "<Scheduled Task>"
$Task.Parameters("NewName") = "Test123"
Error ParameterizedPropertyAssignmentFailed
---
$Task = Get-QADObject "<Scheduled Task>"
$Task.Put("NewName, "test123")
Error MethodNotFound
---

Regards
BEN


  • Hi Ewans,

    no, sorry.

    I try to set the Parameters from an external Shell.

    The Post is the Taskscript to read the parameters, that is my next step ;-)

    Regards
    BEN
  • Hi Ben,

    Not sure about through Powershell but it looks reasonably easy through vbscript, is that an option maybe:

    Set objSchT = GetObject("EDMS://CN=MyTask,CN=Scheduled Tasks,CN=Server

    Configuration,cn=Configuration")
    objSchT.Parameters("Par1") = "100"
    objSchT.SetInfo

    Thanks,
    Ewan

  • Yes, that's what i also found.

    But i couldn't do this in PoSH.
  • For whatever reason, I find teh VBS method to be much simpler -- but here's a sample section from a PowerShell Scheduled Task that we are running in ARS 6.7:

    All values (OverwriteFile, LogFilePath, LogFileName, Environment) are set via the GUI for the SchTask and read in at runtime...

    Just plop your "Work Code" after this section that reads in your parameters...

    Hope that helps you out...

    ---Clip---

    #Read in the Parameters for the Task
    $objTask = [ADSI]$Task.AdsPath
    $params = $objTask.InvokeGet("Parameters")

    $params | ForEach-Object -Process {
        if ($_.'Name' -eq "OverwriteFile")
        {
            $SetOverWritePolicy = [string]$_.'Value'
        }
        elseif ($_.'Name' -eq "LogFilePath")
        {
            $strLogFilePath = [string]$_.'Value'
        }
        elseif ($_.'Name' -eq "LogFileName")
        {
            $strLogFile = [string]$_.'Value'
            $strLogBackup = $strLogFile + "_backup"
        }
        elseif ($_.'Name' -eq "Environment")
        {
            $Environment = [string]$_.'Value'
        }
    }

    ---End---

  • The above code wouldn't work for me in ARS 6.5. I've resorted to reading the edsaParameters value directly. The below code will create a $params object with properties on that object corresponding to the parameter names configured for the scheduled task. Access the parameters like this: $params.MyFirstParamater  $params.AnotherParameter

    #Read in the Parameters for the Task,

    #add them as properties on a $params object.

    $objTask = [ADSI]$Task.AdsPath

    $params = New-Object PSObject

    $objTask.edsaParameters| %{

        $xParameter=([xml]$_).DocumentElement

        Add-Member -InputObject $params NoteProperty $xParameter.Name $xParameter.'#text'

    }

  • Set-QADObject -Identity $NewTaskObjDN -ObjectAttributes @{edsaParameters=$edsaParameters}

    In this case I copied the parameters from one task to another.  The parameters are stored as an XML string so you could ( not tested ) construct this as follows:

    $edsaParameters += "<DBName>DataBaseName\A</DBName>"

     

  • Here's a link to the way I now do this in all of my ARS scheduled tasks : clan8blog.wordpress.com/.../
    if you want to store an LDAPSearch path though you need some additional code which is discussed in this post : clan8blog.wordpress.com/.../