Product: PowerShell Universal
Version: 4.2.9
When using Invoke-PSUScript, i always seem to get an error stating that a parameter cannot be found, it’s always the first parameter after the Invoke-PSUScript.
e.g.
Invoke-PSUScript -Name MyOtherScript.ps1 -from "address1@domain.co.uk" -to "address2@domain.co.uk" -subject "mySubject" -body "Message here"
In this case i get the error
[error] A parameter cannot be found that matches parameter name 'from'.
But if i switch the order of the parameters, it will error about whichever parameter i put first.
If i don’t use Invoke-PSUScript and instead add the code im calling as a Function within the same script, it works fine?
Is there an issue with the way Invoke-PSUScript is handling the first parameter?
JDobbsy1987:
Invoke-PSUScript
I dont see the -Script parameter. Try declaring a script and see if that parameter picks up the custom parameters.
From the docs…
PS C:\> $Script = Get-PSUScript -Name 'Script1.ps1'
PS C:\> Invoke-PSUScript -Script $Script -Parameter1 123 -Parameter2 "Test"
Matt.Harris:
the docs…
I have another Invoke-PSUScript that used the -Name parameter to specify the name of the script I’m calling but having checked the docs i can see it says to use -Script.
I have updated my script to use the -Script parameter but get the same issue.
Script is:
Invoke-PSUScript -Script 'Send-MailgunEmail.ps1' -from "address1@domain.co.uk" -to "address2@domain.co.uk" -subject "my subject" -body "message here"
Gives me the error
[error] A parameter cannot be found that matches parameter name 'from'.
Changing it to
Invoke-PSUScript -Script 'Send-MailgunEmail.ps1' -to "address2@domain.co.uk" -from "address1@domain.co.uk" -subject "my subject" -body "message here"
Results in the error
[error] A parameter cannot be found that matches parameter name 'to'.
try:
$Script = Get-PSUScript -Name 'Send-MailgunEmail.ps1'
Invoke-PSUScript -Script $Script -from "address1@domain.co.uk" -to "address2@domain.co.uk" -subject "my subject" -body "message here"
If that doesn’t work then return the output of the 1st line.
Just tried that but get the same errors regarding the first parameter
Can you return the output of the cmdlet Get-PSUScript
Yes, the output is
[information] Id : 6
[information] Name : Send-MailgunEmail.ps1
[information] OldName :
[information] Description : Send-MailgunEmail.ps1
[information] CreatedTime : 24/01/2024 09:47:10
[information] ManualTime : 0
[information] TimeOut : 0
[information] CommitId :
[information] Content : function Send-MailgunEmail {
[information] param(
[information] [string]$From,
[information] [string]$To,
[information] [string]$Subject,
[information] [string]$Body1,
[information] [string]$Body2,
[information] [string]$Body3,
[information] [string]$Domain
[information] )
[information] <#
[information] $ApiKey = "apikeywashere"
[information] $BasicAuth = [System.Convert]::ToBase64String([
[information] System.Text.Encoding]::ASCII.GetBytes($ApiKey))
[information] $Headers = @{
[information] Authorization = "Basic $BasicAuth"
[information] }
[information] $Url =
[information] "https://api.eu.mailgun.net/v3/$Domain/messages"
[information] $Body = @{
[information] from = $From
[information] to = $To
[information] subject = $Subject
[information] template = 'genericmessage'
[information] "h:X-Mailgun-Variables" = "{
[information] ""EMAILCONT1"": ""$Body1"",
[information] ""EMAILCONT2"": ""$Body2"",
[information] ""EMAILCONT3"": ""$Body3""
[information] }"
[information] }
[information] Invoke-RestMethod -Uri $Url -Method Post
[information] -Headers $Headers -Body $Body
[information] #>
[information] }
[information] ScriptParameters : {}
[information] Identity : PowerShellUniversal.Identity
[information] Status : Draft
[information] Tag :
[information] FullPath : Send-MailgunEmail.ps1
[information] RequiredPowerShellVersion :
[information] Environment :
[information] ErrorAction : Continue
[information] InformationAction : SilentlyContinue
[information] Verbose : False
[information] Debug : False
[information] CommitNotes :
[information] DisableManualInvocation : False
[information] MaxHistory : 100
[information] ConcurrentJobs : 100
[information] Credential :
[information] AccessControls : All
[information] RetryLimit : 0
[information] Anonymous : False
[information] DiscardPipeline : False
[information] LongDescription :
[information] Links : {}
[information] Examples :
[information] DefaultParameterSet :
[information] LoadProfile : False
[information] WorkingDirectory :
[information] ParameterSets : {}
[information] Folder :
[information] OldFolder :
[information] ReadOnly : False
[information] ResolvedPath : C:\ProgramData\UniversalAutomation\Repository\Send-
[information] MailgunEmail.ps1
[information] Module :
[information] Command :
[information] Role :
[information] PreviousContent : function Send-MailgunEmail {
[information] param(
[information] [string]$From,
[information] [string]$To,
[information] [string]$Subject,
[information] [string]$Body1,
[information] [string]$Body2,
[information] [string]$Body3,
[information] [string]$Domain
[information] )
[information] <#
[information] $ApiKey = "apikeywashere"
[information] $BasicAuth = [System.Convert]::ToBase64String([
[information] System.Text.Encoding]::ASCII.GetBytes($ApiKey))
[information] $Headers = @{
[information] Authorization = "Basic $BasicAuth"
[information] }
[information] $Url =
[information] "https://api.eu.mailgun.net/v3/$Domain/messages"
[information] $Body = @{
[information] from = $From
[information] to = $To
[information] subject = $Subject
[information] template = 'genericmessage'
[information] "h:X-Mailgun-Variables" = "{
[information] ""EMAILCONT1"": ""$Body1"",
[information] ""EMAILCONT2"": ""$Body2"",
[information] ""EMAILCONT3"": ""$Body3""
[information] }"
[information] }
[information] Invoke-RestMethod -Uri $Url -Method Post
[information] -Headers $Headers -Body $Body
[information] #>
[information] }
Try
Invoke-PSUScript -id 6 -from "address1@domain.co.uk" -to "address2@domain.co.uk" -subject "my subject" -body "message here"
-Script accepts a scriptblock.
-ID accepts the ID of the script you are trying to run
Same issue im afraid, the invoking of the script works, using the name and ID, just always complains about the first parameter
How bizarre, What version of PSU are you using?
I was on 4.2.9 when i posted but upgraded to 4.2.11 to see if that would help, it didn’t
Might raise it with support as really struggling to see why this doesn’t work but another Invoke-PSUScript does work
Especially when if i run the code within the same script by calling the function it works just fine, i just wanted to call this function from another script as many of my scripts will use this function so nice to have it once rather than in every script.
The output of Get-PSUScript shows an empty array for ‘ScriptParameters’. I think your issue is that you have a function declaration inside that script file. The function has parameters, but the script file itself does not. Remove the function declaration and just leave the parameter block and body.
1 Like
This was the issue, i only feel a little bit stupid now
Thank you very much!
1 Like