I have a PowerShell script that I'm trying to run, but I keep getting some confusing errors. The script is linked here: [push-Files.ps1](https://github.com/Team503/POSH-scripts/blob/main/push-Files.ps1). The errors I'm encountering reference parameters that I can't even find in my script. One error says: "Cannot bind parameter 'RemainingScripts'. Cannot convert the '-join' value of type 'System.String' to type 'System.Management.Automation.ScriptBlock'." Another warning says it couldn't capture the HTTP response body because it's calling a method on a null-valued expression. There's also an error indicating it can't bind the parameter 'Date' and the value isn't recognized as a valid DateTime. Finally, I get a message about the 'enableVerboseMode' parameter not being a valid boolean. I've checked and rechecked my code, and rebooted, even tried it on a different server but still no luck. I'm really at a loss here and would love any insights before I start over from scratch!
3 Answers
Just a note, I didn't see your code in detail. What does line 315 of your log-activity function look like? That might give more insight into what's going wrong. Also, have you checked if anything in the job you're getting data from is returning unexpected values?
It sounds like the issue might be related to how you're using the foreach loop. The 'RemainingScripts' error often comes up in that context when the foreach is trying to process an empty or misplaced parameter. Check the documentation for the foreach object command if you haven't already. That said, make sure you're using a compatible version of PowerShell too; some scripts just won't work properly on older versions.
Also, the issue might be stemming from the JSON definitions. Since you mentioned having copied them over, that could definitely be causing unexpected errors if there's something off with how they're structured.
That's interesting! I found that the JSON definitions were indeed messing with the execution. Once I shortened or removed them, things started working again.
Have you confirmed there's no syntax error in your script? Sometimes, PowerShell will throw misleading error messages if there's an underlying issue that's just not evident right away. Also, since line 315 is mentioned in the errors, checking that part of the log-activity might give you more clues about what's going wrong. But honestly, it could just be that PowerShell isn't playing nice with the data types being passed around.
Definitely! I thought my syntax was fine, but apparently it was a mix-up with the JSON definitions that caused a whole stack of errors.
Thanks for checking! The code is actually linked right at the start of my post. As for log-activity, it handles logging as you could guess, but line 315 might be where the problem is hiding.