<#
.SYNOPSIS
    Run a single on-demand VMware incremental backup
.DESCRIPTION
    Run a single on-demand VMware incremental backup
.EXAMPLE
    Start-ITDCohesityOnDemandVMIncremental -ComputerName itdxyz.nd.gov
.NOTES
    General notes
.COMPONENT
    Cohesity
.ROLE
    The role this cmdlet belongs to
.FUNCTIONALITY
    The functionality that best describes this cmdlet
#>
function Start-ITDCohesityOnDemandVMIncremental {
    [CmdletBinding()]
    Param (
        
        [Parameter()]
        $ComputerName        
    )
    
    begin {
    }
    
    process {
        $CohesityVMwareVM = Get-CohesityProtectionSourceObject | Where-Object Name -eq $ComputerName #| Select-Object -Unique Id, Name, Environment, ParentId
        Start-CohesityProtectionJob -Id (Get-CohesityProtectionJob | Where-Object sourceIds -Match $CohesityVmwareVM.parentId) -SourceIds $CohesityVMwareVM.id
    }
    
    end {
        
    }
}

<#
.SYNOPSIS
    Create a Protection Group based on VMware AppName Tag, one protection group for each VMware source.
.DESCRIPTION
    Long description
.EXAMPLE
    New-ITDCohesityProtectionGroup -AppName ITD-POC-zmeier
.NOTES
    General notes
.COMPONENT
    The component this cmdlet belongs to
.ROLE
    The role this cmdlet belongs to
.FUNCTIONALITY
    The functionality that best describes this cmdlet
#>
function New-ITDCohesityProtectionGroupWIP {
    [CmdletBinding()]
    Param (
        [Parameter()]
        [string[]]
        $AppName,

        [switch]
        $NewBuildsOnly
    )
    
    begin {
    }
    
    process {
        $AllProtectionSourceObject = Get-CohesityProtectionSourceObject
        # create protection group based on appname, exclude placeholders
        ForEach ($app in $AppName) {
            $ProtectionJob = $null

            $SourceObjects = $AllProtectionSourceObject | Where-Object Name -eq $app
            $StartHour = Get-Random -Minimum 18 -Maximum 23
            $StartDateTime = ([DateTime]::Today.AddHours($StartHour)).AddMinutes(30)
            ForEach ($SourceObject in $SourceObjects) {
                $Source = Get-CohesityProtectionSourceObject -Id $SourceObject.parentId
                switch ($Source.environment) {
                    'kVMware' {
                        $ProtectionJobName = ($app + "@" + $Source.Name.split('.')[0])
                    }
                    'kPhysical' {
                        $ProtectionJobName = ($app + "@" + "physical")
                    }
                }

                $SRMTagPlaceholderObject = $AllProtectionSourceObject | Where-Object {$_.Name -eq "Placeholder" -and $_.ParentId -eq $SourceObject.parentId}

                New-CohesityProtectionJob -Name $ProtectionJobName `
                    -PolicyName "ITD-Bronze" `
                    -VmTagIds $SourceObject.Id `
                    -ParentSourceId $SourceObject.parentId `
                    -ExcludeVmTagIds $SRMTagPlaceholderObject.id `
                    -Environment $Source.environment `
                    -Timezone "America/Chicago" `
                    -ScheduleStartTime $StartDateTime `
                    -StorageDomainName DefaultStorageDomain `

                $indexingPolicy = [PSCustomObject]@{
                    disableIndexing = $false;
                    allowPrefixes   = @('/');
                    denyPrefixes    = @('/$Recycle.Bin', '/Windows', '/ProgramData', '/System Volume Information', '/Users/*/AppData', '/Recovery', '/usr', '/sys', '/proc', '/lib', '/grub', '/grub2', 'opt/splunk', '/splunk')
                }

                $ProtectionJob = Get-CohesityProtectionJob -Names $ProtectionJobName
                $ProtectionJob | Add-Member -MemberType NoteProperty -Name indexingPolicy -Value $indexingPolicy
                Set-CohesityProtectionJob -ProtectionJob $ProtectionJob -Confirm:$false
            }
        }
    }
    
    end {
        
    }
}