how can i make a function for day

Welcome Forums General PowerShell Q&A how can i make a function for day

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
8 months, 1 week ago.

  • Author
    Posts
  • #96066

    Participant
    Points: 0
    Rank: Member
     $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
    Points: 25
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

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

    • #96092
      Jon

      Participant
      Points: 25
      Rank: Member

      Are you asking if you can nest functions?

    • #96099

      Participant
      Points: 0
      Rank: Member

      yea indeed

  • #96125

    Participant
    Points: 227
    Helping Hand
    Rank: 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.

The topic ‘how can i make a function for day’ is closed to new replies.