Author Posts

March 15, 2018 at 4:01 pm

 $thisplan = New-Object PSObject
Add-Member -InputObject $thisplan -MemberType NoteProperty -Name PlanID -Value $planid
Add-Member -InputObject $thisplan -MemberType NoteProperty -Name PlanName -Value $            
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)
        $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

March 15, 2018 at 4:13 pm

Whatever code you want to be a function do this

Function NameOfFunction

Then whenever you want to run the function "NameOfFunction"

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

March 15, 2018 at 5:36 pm

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

March 15, 2018 at 7:02 pm

Are you asking if you can nest functions?

March 16, 2018 at 12:42 am

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.