What is the maximum number of arguments a Powershell V2.0 script will accept when invoked from the command line or a batch file?
The theoretical max would be 2 GB worth of arguments.  :-)  That comes from the fact that unmapped args in a function map to an Object array ($args) and arrays in .NET 2.0/4.0 (with 4.5 installed) can be indexed up to Int32.MaxValue.  From what I understand the actual limit is somewhat lower than that depending on the actual type.  FWIW I can create an array of object 128MB in size in PowerShell.  I think the more realistic limit to the number of arguments are limitations on the command line length.  At one point in time cmd.exe had a max line length of 8191.  I'm not sure what PowerShell's max is but I would guess it would be similar to cmd.exe's max.  Also, if an external process needs to be started then these shells go through the CreateProcess API it has a limit of 32,767 characters for the command line passed to the process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With