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.
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.
$force_push = if ($Env:au_ForcePush) { '--force' } else { '' }
choco push package.nupkg --api-key KEY --source URL $force_pushPowerShell 5.1: Works (empty string filtered) PowerShell 7: Fails with "File specified is either not found or not a .nupkg file"
$force_push = if ($Env:au_ForcePush) { '--force' } else { $null }
choco push package.nupkg --api-key KEY --source URL $force_pushPowerShell 5.1: Works ($null filtered)
PowerShell 7: Works ($null filtered)
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 arg3Expected 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)
- What's New in PowerShell 7.3 - PSNativeCommandArgumentPassing
- Breaking change introduced in PowerShell 7.3.0
- Affects all external command invocations with empty string arguments