how can i make a function for day

This topic contains 5 replies, has 3 voices, and was last updated by  postanote 2 months, 1 week ago.

  • Author
    Posts
  • #96066

    jokkegian
    Participant
     $thisplan = New-Object PSObject
    Add-Member -InputObject $thisplan -MemberType NoteProperty -Name PlanID -Value $planid
    Add-Member -InputObject $thisplan -MemberType NoteProperty -Name PlanName -Value $plan.name            
    Add-Member -InputObject $thisplan -MemberType NoteProperty -Name SessionPassword -Value $sessionpass
    
     $schedule = $plan.backupConfiguration.advanceSchedule.periodSchedule 
        #DAY section #######
         add-Member -InputObject $thisplan -MemberType NoteProperty -Name DayRetention -Value $schedule.daySchedule.retentionCount
          if ($schedule.daySchedule.retentionCount -gt 0)
          {
            $dstart = udptime($schedule.daySchedule.dayTime)
          }
          else
          {
            $dstart = ""
          }
          Add-Member -InputObject $thisplan -MemberType NoteProperty -Name DayStart -Value $dstart
    ##########end day section######
    
    
    is there a way to make a function for the #day section? This is a small part from my script.
    the day section occurs several times in my script
    
  • #96068

    Jon
    Participant

    Whatever code you want to be a function do this

    Function NameOfFunction
    {
    code
    }
    

    Then whenever you want to run the function "NameOfFunction"

    For organizational purposes, I like to put all my functions at beginning of the script.

    • #96077

      jokkegian
      Participant

      how can i do it when the other block code is also in a function?

    • #96092

      Jon
      Participant

      Are you asking if you can nest functions?

    • #96099

      jokkegian
      Participant

      yea indeed

  • #96125

    postanote
    Participant

    Sure you can and there is plenty documentation the shows this type of thing.
    Yet, the question is, based on what you are after, should you nest.
    As with many things. Just because you can do something, does not mean that you should.
    Be cognizant of doing anything, unless you know what the outcome will be and / or have a very solid rationale as for why.

You must be logged in to reply to this topic.