Private/Log-Utils.ps1

function Get-LogDir
{
    ##############################################################################
    #.SYNOPSIS
    # Gets Sitecore Deploymeny PowerShell log directory from existing directory.
    #
    #.DESCRIPTION
    # Gets Sitecore Deploymeny PowerShell log directory from existing directory
    # Log directory name: _SitecoreDeploymentPS
    #
    #.PARAMETER Directory
    # Root directory used for getting a log directory (absolute path)
    #
    #.EXAMPLE
    # $directory = "C:\root"
    # $logDir = Get-LogDir -Directory $directory
    ##############################################################################

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        [ValidateScript({
            if (Test-Path $_) { $true }
            else { Throw "The $_ path is not valid. Please, provide a valid value." }})]
        [string]$Directory
    )

    $logsDirectory = Join-Path -Path $Directory -ChildPath "_SitecoreDeploymentPS"

    if (Test-Path $logsDirectory) 
    {
        return $logsDirectory
    }
    else 
    {
        return $null
    }
}

function New-LogDir
{
    ##############################################################################
    #.SYNOPSIS
    # Creates Sitecore Deploymeny PowerShell log directory in existing directory.
    #
    #.DESCRIPTION
    # Creates Sitecore Deploymeny PowerShell log directory in existing directory
    # Log directory name: _SitecoreDeploymentPS
    #
    #.PARAMETER Directory
    # Root directory used for creating a log directory (absolute path)
    #
    #.EXAMPLE
    # $directory = "C:\root"
    # $logDir = New-LogDir -Directory $directory
    ##############################################################################

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        [ValidateScript({
            if (Test-Path $_) { $true }
            else { Throw "The $_ path is not valid. Please, provide a valid value." }})]
        [string]$Directory
    )

    $logsDirectoryPath = Join-Path -Path $Directory -ChildPath "_SitecoreDeploymentPS"
    
    if (!(Test-Path $logsDirectoryPath))
    {
        $logsDirectory = New-Item -Path $Directory -Name "_SitecoreDeploymentPS" -ItemType Directory
        return $logsDirectory.FullName
    }

    return $null
}

function New-ExcludedDirsFile
{
    ##############################################################################
    #.SYNOPSIS
    # Creates a file with excluded in backup folders.
    #
    #.DESCRIPTION
    # Creates a file with excluded in backup directories.
    # File name: ExcludedDirectories.txt
    #
    #.PARAMETER Directory
    # Root directory used for creating a file with excluded directories (absolute path)
    #
    #.PARAMETER ExcludedDirs
    # Excluded directories
    #
    #.EXAMPLE
    # $directory = "C:\backup\2016-06-16 16-34"
    # $excludedDirs = @("C:\website\App_Data\MediaCache", "_DEV", "_CMP", "upload", "temp", "sitecore", "sitecore modules", "sitecore_files")
    # $excludedDirsFile = New-ExcludedDirsFile -Directory $directory -ExcludedDirs $excludedDirs
    ##############################################################################

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        [ValidateScript({
            if (Test-Path $_) { $true }
            else { Throw "The $_ path is not valid. Please, provide a valid value." }})]
        [string]$Directory,

        [string[]]$ExcludedDirs
    )

    if($ExcludedDirs.count -gt 0)
    {
        $excludedDirsFile = New-Item -Path $Directory -Name "ExcludedDirectories.txt" -ItemType File

        if ($excludedDirsFile) 
        {
            $ExcludedDirs | Out-File -FilePath $excludedDirsFile.FullName
            return $excludedDirsFile.FullName
        }
    }

    return $null
}

function Get-ExcludedDirs
{
    ##############################################################################
    #.SYNOPSIS
    # Gets excluded directories from excluded directories file
    #
    #.DESCRIPTION
    # Gets excluded directories from excluded directories file
    # File name: ExcludedDirectories.txt
    #
    #.PARAMETER Directory
    # Root directory used for getting ExcludedDirectories.txt (absolute path)
    #
    #.EXAMPLE
    # $directory = "C:\backup\2016-06-16 16-34"
    # $excludedDirs = Get-ExcludedDirs -Directory $directory
    ##############################################################################

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        [ValidateScript({
            if (Test-Path $_) { $true }
            else { Throw "The $_ path is not valid. Please, provide a valid value." }})]
        [string]$Directory
    )

    $excludedDirs = @()

    $excludedDirsFilePath = Join-Path -Path $Directory -ChildPath "ExcludedDirectories.txt"

    if (!(Test-Path $excludedDirsFilePath))
    {
        return $excludedDirs
    } 

    $excludedDirs += Get-Content $excludedDirsFilePath

    return $excludedDirs
}