而另一个Powershell脚本只有在计划时才会发出

我阅读了关于Powershell和计划任务的所有信息。 试过每一个可能看起来是一个解决scheme的位。

不幸的是,我只是不能让PS脚本从Windows任务调度程序调用后, 显然运行正常。 我显然不具备处理这一点的知识。

如果从运行VirtualBox的服务器(Win 2012)手动启动,脚本工作正常。 没有AD只是在这里运行Virtual Box,最终用作公共共享(一个独特的用户:pipe理员)

  • PS脚本停止在同一台服务器上运行的Virtual Box虚拟机,将完整的文件夹robocopy到一个USB外部驱动器E :(大约90分钟),然后重新启动虚拟机,然后再次复制到外部HD复制到另一台机器服务器2012通过networking(Z :)。

一些线索:我只是不明白,有些testing不会返回相同的。 例如 :

$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" 

是一个让我看到一些价值演变的痕迹。 当手动运行脚本时,test-Path始终为true (正常)$ destination_srv2_root is =“z:\ VMbackup”,Z:是以前对第二台服务器的净使用的结果。 但从调度程序运行时变成错误

并且对同一个文件夹txt日志文件的out-file被正确写入,但是相同的out-file到外部HD(e:…)根本不起作用(文件未被创build)。 这就像PS脚本存在并启动的VirtualBox文件夹外面一样。 但没有控制台,没有错误,什么都没有

试图使用每种风格的最后一次尝试:

  %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy unrestricted -noexit & .\testPS.ps1 

感谢任何帮助。

在这里输入图像描述 在这里输入图像描述

映射的驱动器不太可能工作。 映射的驱动器是每个用户,甚至更细粒度; 它们不是在管理用户的特权和非特权令牌之间共享的。

您应该在脚本中使用UNC路径。 为了便于替换,请在您的脚本中创建一个映射到UNC路径的PSDrive。

 New-PSDrive -Name Z -PSProvider FileSystem -Root \\root\share 

当然,运行计划任务的用户必须具有访问该UNC路径的权限。

这是代码的一部分..

 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