jeudi 26 octobre 2017

If Statement Not Running Within ForEach

For some reason my if statement is not running properly inside of my ForEach statement. The only reason I could think it would be doing this is if the ForEach statement was stopping after the ${Source} declaration, which would be odd.

function new-Backup {
ForEach ($Source in $Sources){
    ${FileName} = Split-Path ${Source} -Leaf

    Add-Content ${Log}\${Timestamp}.log "[Information] $(Get-Timestamp): Backup Script Running..."
    Add-Content ${Log}\${Timestamp}.log "[Information] $(Get-Timestamp): Creating archive: ${FileName}-${TimeStamp}.zip"

    WinRAR a -ep ${Destination}\${FileName}-${TimeStamp}.zip $Source

    If(Test-Path -Path ${Destination}\${Filename}-${Timestamp}){
        Add-Content ${Log}\${Timestamp}.log "[Information] $(Get-Timestamp): Successfully created archive: ${FileName}-${TimeStamp}.zip"
    Else{
        Add-Content ${Log}\${Timestamp}.log "[Information] $(Get-Timestamp): Failed to create archive: ${FileName}-${TimeStamp}.zip"
    }
    }
}

Aucun commentaire:

Enregistrer un commentaire