4

I am working on PowerShell script that requires me to pass string as param. The string is a comma seperated list of user names. I get the error when i have 100+ user names. But i get no error if the string has less then 100 users. See below. I have tried to pass this value using array with no luck. What is the character limitation for this param and how can i solve this. I am using this in ServiceNow Run PowerShell script. That value of the parameter is passed by ServiceNow using a comma seperated value.

Param(
    [string]$itil_users_a = "A.Syafiq,Aaron.Brown,Aaron.Reynnie,Abd.Jalil,Abdu.Hijazi,Abdul.Onny,Abdullah.Ammar,Abel.Muataco"    
    )
deshergan
  • 73
  • 1
  • 1
  • 5
  • You have a trailing square bracket. Is that a typo? Where are you calling this script from? – Matt Mar 30 '15 at 19:29
  • I ask because this should not be a PowerShell limitation but a cmd.exe one maybe. Also you could consider using text file input for something like this. – Matt Mar 30 '15 at 19:38
  • Yes, that was a typo, i have corrected it. I am using this in ServiceNow Run PowerShell script. That value of the parameter is passed by ServiceNow using a comma seperated value. – deshergan Mar 30 '15 at 20:11
  • Command line length is usually determined by the caller. How are you launching the script? A batch file has a shorter limit than a powershell script. – Ryan Bemrose Mar 30 '15 at 21:11
  • Do you have an example of the error text? – Booga Roo Mar 31 '15 at 01:16
  • Related: https://stackoverflow.com/questions/61843611/powershell-to-avoid-cmd-8191-character-limit – Gabriel Devillers Oct 13 '22 at 17:25

2 Answers2

10

You may be running into the maximum length for command lines - 8191 chars. See this KB article on max command line length.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Yes, this is exactly what I was experiencing. I just thought for Power Shell, it may not be the case. Thanks for the answer. – deshergan Mar 31 '15 at 13:49
  • 10
    it's really a shame that still with Windows 10, one has to face such limitation. – Nabil Jul 07 '19 at 15:56
  • 3
    any ideas about getting round this that aren't just breaking up the command? – niico Jun 03 '20 at 15:51
  • Has anyone else tried using Powershell in Windows Terminal to run longer commands? I tried that earlier today for a command that was >9000 characters long, and from what I recall it succeeded when run there. It would be odd if Windows Terminal found a way to bypass that limit though, so maybe I'm remembering wrong. – Venryx Aug 29 '21 at 08:06
  • 6
    This answer was posted in 2015 and it's 2021 now. Is there any update on how to get around this problem? – Ray Sep 13 '21 at 16:55
  • @Ray You can use pipe to get around this. See my answer for further details. – dns Oct 06 '22 at 17:57
0

You can use pipe to get around this.

I can insert a million rows to sqlite3.exe using pipe.

Rather than sqlite.exe .\ex1.db $sql which will return error. You can use this: $sql | sqlite.exe .\ex1.db

The $sql variable can have more than a million rows (so it's more than 8191 characters).

dns
  • 2,753
  • 1
  • 26
  • 33