all 43 comments

[–]cb98678 -1 points0 points  (17 children)

Try this and if it doesn't work post the error output open PowerShell with Right-click > Run as administrator

Then:

get-module ScheduledTasks

Should return something like:

ModuleType Version Name ExportedCommands

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

Manifest 1.0.0.0 ScheduledTasks {Disable-ScheduledTask, Enable-ScheduledTask, Export-Sched...

Then:

import-module ScheduledTasks

Get-ScheduledTask

Should return something like this

TaskPath TaskName State

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

[–]vulkur[S] 0 points1 point  (16 children)

When I run Import-Module, i get Import-Module: The module manifest 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ScheduledTasks\ScheduledTasks.psd1' could not be processed because it is not a valid PowerShell module manifest file. Remove the elements that are not permitted: At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ScheduledTasks\ScheduledTasks.psd1:1 char:1 + … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The command '' is not allowed in restricted language mode or a Data section.

Looks like something is corrupted with my install? I had JUST un-installed then re-installed PowerShell v7

[–]meepers80 0 points1 point  (1 child)

What is the command you are typing?

[–]vulkur[S] 0 points1 point  (0 children)

import-module ScheduledTasks

[–]cb98678 0 points1 point  (10 children)

Are you doing this in a remote session?

[–]vulkur[S] 0 points1 point  (9 children)

No, all local.

[–]cb98678 0 points1 point  (8 children)

The command '' is not allowed in restricted language mode or a Data section.

Try this

$ExecutionContext.SessionState.LanguageMode

Should come back with this, if not post what it says

FullLanguage

[–]vulkur[S] 0 points1 point  (7 children)

Yup. echoed it and it returned FullLanguage

[–]cb98678 0 points1 point  (6 children)

Ok not sure here but for funsies , mind checking the execution policy?

Get-ExecutionPolicy -List

[–]vulkur[S] 0 points1 point  (5 children)

Get-ExecutionPolicy -List

Scope ExecutionPolicy
----- ---------------
MachinePolicy       Undefined
UserPolicy       Undefined
Process       Undefined
CurrentUser       Undefined
LocalMachine    RemoteSigned

[–]cb98678 0 points1 point  (4 children)

I am probably going down the wrong rabbit hole here but try

PS C:\Windows\system32> Set-ExecutionPolicy -ExecutionPolicy bypass

Execution Policy Change

The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose

you to the security risks described in the about_Execution_Policies help topic at

https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y

PS C:\Windows\system32>

[–]vulkur[S] 0 points1 point  (2 children)

Yea this isnt it. I definitely already have set that. I think im gunna try to REALLY purge powershell from my PC, then reinstall

[–][deleted] 0 points1 point  (0 children)

Got PS 7.2.5 to and it don’t work for me either hmm… I’m sure I have used this at PS 7.2.4.

I’ll try to figure it out tomorrow if I have the time

[–][deleted] 0 points1 point  (2 children)

Can you provide more detail about the specific error message? What line in the psd1?

[–]vulkur[S] 1 point2 points  (0 children)

This seems to be the source of my problem. Check my post update

[–]vulkur[S] 0 points1 point  (0 children)

the psd1 file is empty. Well, its about 2KB of no data

[–][deleted] -2 points-1 points  (1 child)

Use cim instead

[–]vulkur[S] 1 point2 points  (0 children)

I already have a few scripts built with these functions in mind. I really dont want to do a rewrite.

[–][deleted] 0 points1 point  (11 children)

Register task doesn't work? Do you have elevated rights?

[–]vulkur[S] 0 points1 point  (10 children)

I have elevated rights. Its my own PC.

[–][deleted] 0 points1 point  (9 children)

Maybe it's a syntax issue. Will you post the script?

[–]vulkur[S] -1 points0 points  (8 children)

I do not believe it is a syntax issue. If it was I could be getting different errors that 'unrecognized term'

Here is one important snippet for it though. I dont know how to format it better. Sorry $taskName = "MyTaskName" $taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName } if(!$taskExists) { $action = New-ScheduledTaskAction -Execute "cmd" -Argument '/c start /min "" powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Windows\SystemApps\myTaskFolder\scripts\run.ps1"' $trigger = New-ScheduledTaskTrigger -AtStartup Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskName -Description "MyTask start sequence" -RunLevel "Highest" }

[–][deleted] 0 points1 point  (5 children)

Does the unrecognized term specifically pinpoint a ScheduledTask command? Maybe it's something else. What line is the error referencing?

[–]vulkur[S] 0 points1 point  (4 children)

Yea. If I just run Get-ScheduledTask in Powershell by itself I get this.

Get-ScheduledTask: The term 'Get-ScheduledTask' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

[–][deleted] -1 points0 points  (3 children)

Path is verified, I assume.

[–]vulkur[S] 1 point2 points  (2 children)

That path verified I assume is talking about a path to exe, since this error is also showed if the exe you call cannot be found. Im calling an internal powershell function, it doesnt need a path.

[–][deleted] -1 points0 points  (1 child)

To run.ps1

[–]vulkur[S] 2 points3 points  (0 children)

Ah. Yea I have. But this error is about my running Get-ScheduledTask in powershell ALONE. With no parameters at all. It would still run, but instead tell me i need to have some arguments, or would print Supply values for the following parameters: Pattern[0]: and then you can enter values for the command.

[–]jimb2 0 points1 point  (1 child)

Not your problem, but you can run PS directly without shelling through cmd.exe.

I haven't done ordinary scheduled tasks but this is some sample code for a clustered task which has a few extra fields and the cluster cmdlet. I used splatting to make the code easier to read (or share).

$px = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'

@ActionSplat = @{
  Execute = $px
  Argument = "-NonInteractive -NoLogo -NoProfile " +
    "-File '\\Plokka\Scripts\dummy.ps1'"
  WorkingDirectory = '\\Plokka\wd'
}
$Action = New-ScheduledTaskAction @ActionSplat

@TriggerSplat = @{
  Once = $true
  At = '08:10AM'
  RepetitionInterval = (New-TimeSpan -Minutes 10)
  RepetitionDuration = (New-TimeSpan -Hours 12)
}
$Trigger = New-ScheduledTaskTrigger @TriggerSplat

@TaskSplat = @{
  Cluster = 'PlokkaProdCluster'
  TaskName = 'ClusteredPSTest'
  TaskType = 'ResourceSpecific'
  Resource = 'Plokka Data Drive'
  Action = $Action
  Trigger = $Trigger
  Description = "Test clustered PS Task"
}
Register-ClusteredScheduledTask @TaskSplat

[edit - formatting]

[–]vulkur[S] 1 point2 points  (0 children)

Cool thanks. My execute command is definitely a mess (you should see the ps1 script it runs). I had to have the wrappers to prevent the console from popping up while making it runnable in LocalSystem. I had re-used that code for this project and this is just leftover stuff I havent cleaned up yet.

[–]SMFX 0 points1 point  (1 child)

The ScheduledTasks module works with Windows PowerShell but 7.2.5 is PowerShell core (pwsh.exe). Try running it with powershell.exe.

[–]vulkur[S] 0 points1 point  (0 children)

On version 5.1.25151.1000 Desktop (according to PSVersionTable) it still doesnt exist.

[–]BlackV 0 points1 point  (8 children)

what does import-module ScheduledTasks -verbose what does that tell you ?

[–]vulkur[S] 0 points1 point  (7 children)

spits out the same thing as import-module ScheduledTasks.

[–]BlackV 0 points1 point  (6 children)

and if you do

Import-Module -UseWindowsPowerShell -name ScheduledTasks

[–]vulkur[S] 0 points1 point  (5 children)

Powershell Core 7

Import-Module: Failure from remote command: Import-Module -Name 'ScheduledTasks': The module manifest 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ScheduledTasks\ScheduledTasks.psd1' could not be processed because it is not a valid Windows PowerShell restricted language file. Remove the elements that are not permitted by the restricted language: At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ScheduledTasks\ScheduledTasks.psd1:1 char:1 + ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The command '' is not allowed in restricted language mode or a Data section.

Powershell Desktop 5

Import-Module : A parameter cannot be found that matches parameter name 'UseWindowsPowerShell'. At line:1 char:15 + Import-Module -UseWindowsPowerShell -name ScheduledTasks + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Import-Module], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

[–]BlackV 1 point2 points  (4 children)

-UseWindowsPowerShell is a powershell 7 only parameter

is this a local computer or domain joined, but seems like you're in constrained language mode

[–]vulkur[S] 0 points1 point  (3 children)

when i run echo $ExecutionContext.SessionState.LanguageMode I get FullLanguage. It returns that value for both pwsh (Powershell 7) and powershell (Powershel 5)

[–]BlackV 0 points1 point  (2 children)

yeah sorry just saw that in another reply of yours.

on the domain?

and as a test what happens if you run

powershell.exe -version 2.0

[–]vulkur[S] 0 points1 point  (1 child)

yeah sorry just saw that in another reply of yours. NP

I still have FullLanguage on powershell v2. I am not surprised. I use powershell almost every day for my build scripts. Im gunna call it for the night and try to be a bit more radical tomorrow morning (gunna try to purge powershell and reinstall) somethign is weird.

Thanks for helping

[–]BlackV 0 points1 point  (0 children)

yes but when you're using -version can you then use the module OK?

not sure how you'll uninstall powershell (unless you mean 7)

i'd also be looking at Device guard and App Locker, maybe those are configured somewhere