我正在运行以下PowerShell脚本,该脚本创建了一个Tableau备份,并使用Windows Task Scheduler将其上传到Google Cloud Storage。
#Tableau Server backup
&$tsm maintenance backup -f $Backups_file -d -u $User -p $Password
CD "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin"
$backups_folder = "D:\Tableau Server\data\tabsvc\files\backups\" #default backup path for Tableau installation #&$tsm configuration get -k basefilepath.backuprestore
$filename = get-childitem -path $backups_folder -Filter "*.tsbak" | where-object { -not $_.PSIsContainer } | sort-object -Property $_.CreationTime | select-object -last 1
$fullpath = Join-Path $backups_folder $filename
gsutil cp $fullpath gs://my_bucket/backups #upload the latest backup to GCP我使用以下命令:
powershell -Command "start-process -verb runAs "powershell " -argumentlist "E:\Tableau\test.ps1""这将提示以下消息:

运行脚本,创建备份并将其成功上传到GCS。
现在,我需要使用Windows Task Scheduler自动执行此脚本,如下所示:
Program/script: powershell
Add arguments (optional): -Command "start-process -verb runAs "powershell " -argumentlist "E:\Tableau\test.ps1""

我通过用户系统将任务设置为以最高权限运行:

在这种情况下,什么都不会发生。
我尝试了另一个创建备份但不上传到GCS的命令。当我使用命令powershell -executionpolicy bypass -file 'E:\Tableau\Tableau Backup\test.ps1在CMD上手动运行它时,我得到以下错误:
PS D:\Tableau Server\data\tabsvc\files\backups> powershell -executionpolicy bypass -file 'E:\Tableau\Tableau Backup\test
.ps1'
CommandException: Error opening file "file://D:\Tableau Server\data\tabsvc\files\backups\TableauBackup-2020-06-06.tsbak"
: [Errno 13] Permission denied: u'D:\\Tableau Server\\data\\tabsvc\\files\\backups\\TableauBackup-2020-06-06.tsbak'.因此,很明显,在使用gsutil命令时存在权限错误。当我以管理员身份手动启动我的cmd时,该命令运行得很流畅。
当从非管理员提升的CMD触发时,最后一个命令可以正常工作,但在Windows Task Scheduler中设置时将不起作用:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command "start-process -verb runAs "powershell " -argumentlist "E:\Tableau\test.ps1""我还尝试了this,它不能在任务调度器上工作,当运行到CMD时将手动运行,但也会失败,权限被拒绝,因为我列出了前面的命令:
powershell.exe -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "E:\Tableau\test.ps1"如何正确设置myWindows任务计划程序才能成功运行此脚本?
发布于 2020-06-12 06:33:29
这最终对我起作用了。
Program/script: powershell
Add arguments (optional): -ExecutionPolicy Bypass -command "E:\Tableau\test.ps1 2>&1 > E:\Tableau\test_output.txt"或者在从管理员提升CMD的单个命令中运行:
powershell -ExecutionPolicy Bypass -command "E:\Tableau\test.ps1 2>&1 > E:\Tableau\test_output.txt"真正的问题是我在Google Cloud VM上运行它,我需要更改VM的作用域才能访问所有API。
这样做之后,我就可以成功地运行脚本了。
发布于 2020-10-19 17:29:04
我也无法启动脚本,在繁重的搜索之后一无所获。没有-ExecutionPolicy,没有命令,没有文件,"“和'‘之间没有区别。
我只需将我在parameter2中运行的命令放在参数选项卡中:./scripts.ps1、parameter1、11、scripts.ps1、xx等等。现在调度器可以工作了。Program: Powershell.exe开始位置: C:/location/of/script/
https://stackoverflow.com/questions/62245797
复制相似问题