<# Scheduled Task metadata
General
    SetVMTagAndMoveToAppNameFolder
    run as ndgov\svcitdiaassched
        run whether user is logged on or not
        run with highest privileges
 Triggers
    Daily, 1pm
Actions
    old     powershell.exe -file "D:\PowerShellTasks\SetVMTagAndMoveToAppNameFolder\SetVMTagAndMoveToAppNameFolderTask.ps1"
    new     "C:\Program Files\PowerShell\7\pwsh.exe" -file "F:\PowerShellTasks\SetVMTagAndMoveToAppNameFolder\SetVMTagAndMoveToAppNameFolderTask.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 = "F:\SetVMTagAndMoveToAppNameFolder\Logs\SetVMTagAndMoveToAppNameFolderTask-$Timestamp.log"
Start-Transcript $TranscriptPath

Connect-ITDvCenter -Credential $svcitdvmvcauto

Set-ITDVMwareVMTagFromSharePoint -SharePointCredential $svcitdiaassprw -Verbose

Move-ITDVMwareVMToAppNameFolder -Credential $svcitdvmvcauto -Verbose

Disconnect-VIServer -Server * -Force -Confirm:$false