Getting error: Cannot process the #requires statement because it is not in the correct format

Hello!

Been having a weird issue with one of my scripts in PS Automation, keep getting this error despite not using #requires anywhere in the script and the rest of our scripts work fine.

[3:30:14 PM] [ERR] Cannot process the #requires statement because it is not in the correct format.
The #requires statement must be in one of the following formats:
#requires -shellid ”
#requires -version <major.minor>”
#requires -psedition ”
#requires -pssnapin [-version <major.minor>]”
#requires -modules ”
#requires -runasadministrator”

Anyone have any ideas?

Thanks!

Product: PowerShell Universal
Version: 1.5.8

Could this be a module getting auto-imported?

We don’t use #requires in UA anywhere that I can find.

Very possibly! I went through this morning and slimmed down the script a bit, just have one module it pulls in now, still getting the same error. I can run the script manually on our machine hosting PSU and I am not getting the error which is also strange.

What Environment is your PSU script running in? Is the module it relies on in the PSModulePath for that environment?

Its running in 5.1, the module is a home grown one we made to interact with Ivanti HEAT and its installed to C:\Progam File\WindowsPowershell\Modules.

This is driving me up such a wall I went though each of the commands in the module and searched for #requires and removed anything close, still no dice.

Very weird. Is this the only script that uses that module?

Just trying to think of what the difference between that script and the rest of your scripts are

Yepp! I actually just commented out the few lines that called the module/imported it, still getting the same error so I must have done something exceptionally weird :smiley:

Whoa. Now that’s super weird. I know #requires needs to be at the top of the script but can you try to see if you can catch this error?

try {
# the entire script 
} catch {
    Write-Host $_
}

I’m mostly wondering if you can use that as a debugging step to get some more information (like a stack trace) as to where the error is originating from.

Oook, I think I figured it out and pretty sure it was self inflicted by my bad scripting :slight_smile: . Originally had a param() block at the top of the module and had them laid out like:

    [Parameter(Position = 0, Mandatory = $true, HelpMessage = '')]
    [string]
    $Subject,

When I hacked the Parameter off the top it seems to work as intended. Originally this was going to be a module, but wanted to try putting it in PSU and may have shot myself in the foot during the transition.

2 Likes