Hi All,

Is there anyone who has written a custom function calling powershell that 
returns a value?

The case we are trying to use the puppet module *scheduled_task *and it 
works really well!

The problem is that we don't want to declare our password in the 
declaration so we would like to set username and password with a task 
performed after the task is registered.

Everything works almost fine except for when we set the user and password , 
the next runtime the scheduled_task resource will change back to system 
since nothing is declared.

So everything runs everytime puppet agent runs.

We would like to a custom functions that checks if the scheduled_task is 
created and runing under proper user. If that is the case we dont ned to 
run *scheduled_task *resource.


So in pseudo code something like this:

$result  = sheduledtaskexists("MyMagicTask")

unless $result


  scheduled_task { 'MyMagicTask':
      ensure    => present,
      enabled   => true,
      command   => 'd:\Scheduled_Tasks\MyMagicTask.bat',
      trigger   => {
        schedule   => daily,
        every      => 1,            # Defaults to 1
        start_date => '2011-08-31', # Defaults to 'today'
        start_time => '03:00',      # Must be specified
      }
    }


end




module Puppet::Parser::Functions
      newfunction(:sheduledtaskexists, :type => :rvalue) do |args|

        argument =args[0].to_s() #  "MyMagicTask" 

        cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
-NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command . 
d:\\tools\\check_task_exist.ps1; Task-Exists argument' #should be repla

        value = %x[ #{cmd} ].to_s().chomp
        result = value
      end
end



Powershell snippet... not proper code..


function Task-Exists([string]$taskname)
{       

     [Boolean]$isFound = $false
     [xml]$tasks =  schtasks  /query /TN $taskname /XML

     if($tasks)

    {
        $isFound = $true

    }

       $isFound

}


Has someone done something like this?





-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to