Powershell is unable to execute a routine script, even though it is already enabled to be executed manually. How to solve it?


gfd_sl

Member
Local time
4:42 AM
Posts
1
OS
Windows 10
Hey guys,

I have a script with Powershell routines to run periodically.

I have already applied the following commands to make it run.

Set-ExecutionPolicy Unrestricted

dir c:\Support\routines.ps1 | unblock-file -confirm

This script runs manually without any problems: I open PS and type "c:\Support\routines.ps1" without "". Works 100%

When placed in the task scheduler, the blue screen appears and nothing else happens. It's set up to not be hidden or anything else. It simply must be performed once/day and that's it.

Would anyone know how to make it run on the OS in question (Windows 11), given that the only thing that remains is a blue screen that never closes?

Thanks!
 
Windows Build/Version
Version 11

My Computer My Computer

At a glance

Windows 10Intel i7-377016 GBOnboard
OS
Windows 10
Computer type
PC/Desktop
CPU
Intel i7-3770
Motherboard
ASUS
Memory
16 GB
Graphics Card(s)
Onboard
Sound Card
Onboard
Monitor(s) Displays
LG M228WA
Screen Resolution
1680x1050
Hard Drives
SSD 120 GB + HD 2 TB
Confirm if your task scheduler Action is actually:
Command: powershell.exe​
Parameters: -f C:\Support\routines.ps1​

A common mistake is copying the entire command line into the Command field, instead of splitting it into Command & Parameters.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
<#
.Synopsis
To create an automated task
taskschd.msc

.Description
To create an automated task using PowerShell script

.Parameter
taskName, TaskScript

.Example
TaskScriptCreate -taskName "OSFMount1" -TaskScript '"C:\Program Files\OSFMount\OSFMount.ps1"'
#>

Function TaskScriptCreate {
[CmdletBinding()]
param(
[Parameter(Mandatory = $True)]
[string] $taskName,
[Parameter(Mandatory = $True)]
[string] $TaskScript
)


$TaskArgument = "-Exec bypass -W Hidden -NonI -NoP -File $TaskScript"
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
if ($null -ne $task) { Unregister-ScheduledTask -TaskName $taskName -Confirm:$false }
$action = New-ScheduledTaskAction -Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Argument $TaskArgument
$trigger = New-ScheduledTaskTrigger -AtStartup
$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -Priority 1 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit '00:00:00'
$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings -Description "Run $($taskName) at startup"
Register-ScheduledTask -TaskName $taskName -InputObject $definition

}

---------------------------------------------------

Example: Create a task to run the script at system startup


xxx.ps1

Set-ExecutionPolicy ByPass -Scope Process -Force
Import-Module D:\Documents\WindowsPowerShell\Modules\TaskScript\TaskScript.psm1
TaskScriptCreate -taskName "OSFMount" -TaskScript '"C:\Program Files\OSFMount\osfmount.ps1"'
---------------------------------------------------------

 

My Computer My Computer

At a glance

Microsoft Windows 11 HomeIntel Core i5-13490F2 x 16 Patriot Memory (PDP Systems) PSD516G56...GIGABYTE GeForce RTX 4070 WINDFORCE OC 12G (G...
OS
Microsoft Windows 11 Home
Computer type
PC/Desktop
Manufacturer/Model
MSI MS-7D98
CPU
Intel Core i5-13490F
Motherboard
MSI B760 GAMING PLUS WIFI
Memory
2 x 16 Patriot Memory (PDP Systems) PSD516G560081 6400MT (32-37-37-74); 1.35V)
Graphics Card(s)
GIGABYTE GeForce RTX 4070 WINDFORCE OC 12G (GV-N4070WF3OC-12GD)
Sound Card
Bluetooth Аудио
Monitor(s) Displays
INNOCN 15K1F
Screen Resolution
1920 x 1080
Hard Drives
WD_BLACK SN770 250GB
KINGSTON SNV2S1000G (ELFK0S.6)
PSU
Thermaltake Toughpower GF3 1000W
Case
CG560 - DeepCool
Cooling
ID-COOLING SE-224-XTS / 2 x 140Mm Fan - rear and top; 3 x 120Mm - front
Keyboard
Corsair K70 RGB TKL
Mouse
Corsair KATAR PRO XT
Internet Speed
100 Mbps
Browser
Firefox
Antivirus
Microsoft Defender Antivirus
Other Info
https://www.userbenchmark.com/UserRun/66553205

Latest Support Threads

Back
Top Bottom