How to use scriptparameter when creating a script since scriptblock has no arrgumentlist

@adam

i have a table with multi customers and am trying to create a schedule script for a customer when button is clicked

the script name works fine taking the customer name but the scriptblock will not take $($EventData.Name) cause the scriptblock{} has no argumentlist

how can i pass the customer name to inside the scriptblock when calling the following command

New-PSUScript -Name $($EventData.Name) -ComputerName $Cache:PSUServer -AppToken $Cache:AppToken -ScriptBlock { }

Thank you.

Product: PowerShell Universal
Version: 1.5.19 nightly

I would add a param block to the script and then pass the name in via the schedule.

New-PSUScript -Name $($EventData.Name) -ScriptBlock { param($CustomerName) } 
New-PSUSchedule -Script $($EventData.Name)  -OneTime (Get-Date).AddDays(1) -CustomerName $($EventData.Name)  

You might be able to just create a single script as well.

New-PSUScript -Name CustomScript -ScriptBlock { param($CustomerName) } 

And then the button click just schedules that script.

New-PSUSchedule -Script CustomerScript  -OneTime (Get-Date).AddDays(1) -CustomerName $($EventData.Name)  

@adam

Thank you adam ill test and let you know if found any issues.

Thank you adam it works really appreciate it.

1 Like