I am running the following PowerShell script that creates a Tableau backup and uploads it to Google Cloud Storage using the Windows Task Scheduler.

```
#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

```

I use the command:

```
powershell -Command  "start-process -verb runAs "powershell " -argumentlist "E:\Tableau\test.ps1""

```

Which prompts the following message:

[![Prompt](https://i.stack.imgur.com/HrDOh.png)](https://i.stack.imgur.com/HrDOh.png)

Which runs the script, creates the backup and uploads it to GCS successfully.

Now I need to automate this script using Windows Task Scheduler, which I did as follows:

```
Program/script: powershell
Add arguments (optional): -Command  "start-process -verb runAs "powershell " -argumentlist "E:\Tableau\test.ps1""

```

[![Command setup](https://i.stack.imgur.com/y9tAb.png)](https://i.stack.imgur.com/y9tAb.png)

I setup the task to run with highest privileges by the user SYSTEM:

[![User and privileges](https://i.stack.imgur.com/NWbLY.png)](https://i.stack.imgur.com/NWbLY.png)

In this scenario, nothing happens.

I tried this other command that creates the backups but doesn't upload to GCS. When I run it manually on CMD using the command `powershell -executionpolicy bypass -file 'E:\Tableau\Tableau Backup\test.ps1` I get the following error:

```
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'.

```

So clearly, there's a permissions error when using the gsutil command. When I launch my cmd manually as Administrator, the command runs smoothly.

This last command works smoothly when triggered from a non-administrator elevated CMD but won't work when setup in the Windows Task Scheduler:

```
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command  "start-process -verb runAs "powershell " -argumentlist "E:\Tableau\test.ps1""

```

I also tried [this](https://stackoverflow.com/questions/13015245/powershell-script-wont-execute-as-a-windows-scheduled-task/25172234#25172234) which won't work on the Task Scheduler, will run manually when ran into CMD but will also fail with Permission Denied as the previous command I listed:

```
powershell.exe -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "E:\Tableau\test.ps1"

```

How can I setup properly myWindows Task Scheduler to run this script successfully?