I was going through and adding some formatting to a Powershell script that I had recently rewritten, when it started throwing errors without a single code change.
After pouring over the script to make sure I didn’t make any changes, I started researching size limits of scriptblocks. I found an old article that referenced a size limit of 12,190 bytes. This number didn’t quite add up, because I knew that my previously working scriptblock was larger than that size. I assumed that it’s a discrepancy between Powershell versions. So, after failing to find an official answer, I started some trial and error to find the NEW upper limit.
What I found is that the size limit seems to be around 32,692 bytes! So, if you’re running into the error above, try copying your scriptblock over to Notepad++ and checking it’s length!