<# Scheduled Task metadata
General
    SetVMTagNadMovToAppNameFolder
    run as ndgov\svcitdiaassched
        run whether user is logged on or not
        run with highest privileges
 Triggers
    Daily, 8am
    Disabled
Actions
    powershell.exe -file "D:\PowerShellTasks\SetVMTagAndMoveToAppNameFolder\SyncVMwareAppNameTagsFromSharePoint.ps1"
    
Settings
    allow task to be run on demand
    stop the task if it runs longer than 3 days
    if the running task does not end when requested, force it to stop
#>

$TimeStamp = Get-Date -UFormat "%Y%m%d-%H%M%S"
$TranscriptPath = "D:\PowerShellTasks\SyncVMwareAppNameTagsFromSharePoint\Logs\SyncVMwareAppNameTagsFromSharePointTask-$Timestamp.log"
Start-Transcript $TranscriptPath

try {
    Sync-ITDVMwareSharePointAppNameTags -vCenterCredential $svcitdvmvcauto -SharePointCredential $svcitdiaassprw -Verbose
}
catch {
    Send-MailMessage -To itdvctremailalerts@nd.gov -From itdvmvcp1script@nd.gov -Subject "Task SyncVMwareAppNameTagsFromSharePoint errored" -Body "Task started $TimeStamp.`nCheck logs for further information" -SmtpServer apprelay1.nd.gov
}