I read everything I could about Powershell and scheduled task. Tried every bits of what could appears to be a solution.
Unfortunately I just can't make PS script apparently run correctly once called from the Windows tasks scheduler. I obviously don't have the knowledge to handle this alone.
The script is working fine if manually launched from a server (Win 2012) running a VirtualBox. No A.D just here to run Virtual Box, eventually used as a public share (one unique user: Administrateur)
- PS script stops a Virtual Box VM, running on this same server, robocopy the full folder to an usb external drive E: (almost 90min), then restart the VM, then copy again the copy made to the external HD to another machine server 2012 over the network (Z:) .
Some clues: I just can't understand that some tests don't return the same. For instance :
$IsDestPath2 = test-Path $destination_srv2_root
write-host "IsDestPath2: $IsDestPath2"
Write-Output "$full_dateh - IsDestPath2: $IsDestPath2" | out-File "C:\Program Files\Oracle\VirtualBox\TEST_log.txt"
is a trace making me see some value evolution. when script is manually run, the test-Path is always true (normal) $destination_srv2_root is = "z:\VMbackup", Z: is the result of previous net use to the second server. But become false when run from the scheduler ..!?
And the out-file to a same folder txt log file is correctly writen BUT the same out-file to the external HD (e:...) does not work at all (file not created). It's like nothing exists outside the VirtualBox folder where the PS script exists and is launched. But no console, no error, nothing..
Tried to use every style of arguments last try :
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy unrestricted -noexit & .\testPS.ps1
Thank for any help.
EDIT: here's a part of the code..
date_heure
Write-Host $txt_heure
Write-Host $txt_date
Write-host $full_dateh
#$source = "C:\TestSourceBack"
$source = "C:\VirtualBox VMs"
#destination vise le disque externe amovible
$destination_root = "E:\VMbackup"
$destination = "E:\VMbackup\$thedate"
#destination2 vise le serveur de secours
$destination_srv2_map = "\\192.168.1.94\public"
# Z: pointe directement sur public !!
$destination_srv2_root = "z:\VMbackup"
$destination_srv2 = "$destination_srv2_root\$thedate"
# -------------------------------------------------------------------
Write-Output "====================== DEBUT SAUVEGARDE ==========================" | out-File "$destination_root\backupVM_log.txt" -Append
Write-Output "$full_dateh" | out-File "$destination_root\backupVM_log.txt" -Append
Write-Output "========================================================================" | out-File "$destination_root\backupVM_log.txt" -Append

