Skip to content

Instantly share code, notes, and snippets.

@lukebakken
Last active January 2, 2026 13:24
Show Gist options
  • Select an option

  • Save lukebakken/e7f9ba1fe1c71a46222ddac4b26f9d06 to your computer and use it in GitHub Desktop.

Select an option

Save lukebakken/e7f9ba1fe1c71a46222ddac4b26f9d06 to your computer and use it in GitHub Desktop.
chocolatey-au + PowerShell 7

PowerShell 7 Empty String Argument Passing Test

This test demonstrates the PowerShell 7.3.0+ breaking change in empty string argument passing and verifies that the fix using $null instead of '' works correctly.

The Bug

PowerShell 7.3.0+ changed how empty strings are passed to external commands:

PowerShell 5.1: Empty strings are filtered out PowerShell 7+: Empty strings are passed as ""

This causes choco push to fail with "file not found" errors because it interprets the trailing "" as a filename argument.

Test Results

Before Fix (using '')

$force_push = if ($Env:au_ForcePush) { '--force' } else { '' }
choco push package.nupkg --api-key KEY --source URL $force_push

PowerShell 5.1: Works (empty string filtered) PowerShell 7: Fails with "File specified is either not found or not a .nupkg file"

After Fix (using $null)

$force_push = if ($Env:au_ForcePush) { '--force' } else { $null }
choco push package.nupkg --api-key KEY --source URL $force_push

PowerShell 5.1: Works ($null filtered) PowerShell 7: Works ($null filtered)

Verification

Run this test on both PowerShell 5.1 and 7:

# Test empty string behavior
$empty = ''
Write-Host "Empty string test:"
& echoargs.exe arg1 arg2 $empty arg3

# Test null behavior
$null_var = $null
Write-Host "`nNull test:"
& echoargs.exe arg1 arg2 $null_var arg3

Expected PowerShell 5.1 output:

  • Empty string: 3 args (filtered)
  • Null: 3 args (filtered)

Expected PowerShell 7 output:

  • Empty string: 4 args (passed as "")
  • Null: 3 args (filtered)

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment