Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7719851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:31:05+00:00 2026-06-01T03:31:05+00:00

In short, I’m just looking for the PowerShell equivalent of how a batch file

  • 0

In short, I’m just looking for the PowerShell equivalent of how a batch file can call a script with the same parameters…

"%~dpnx0" %*

…where "%~dpnx0" expands to the absolute path of the script and %* is expanded to the list of parameters. Is there an easy way to replicate %*? Or, at least, a way that works?

I have a PowerShell script that uses the System.Data.OleDb namespace to read data from an Excel workbook. Because there is no 64-bit implementation of the Microsoft Jet provider, the script needs to be run from a 32-bit PowerShell session. Rather than simply having the script fail with an error message if it’s run from a 64-bit session, I’d like to have the 64-bit session invoke the script in and retrieve the results from a 32-bit session. I found that this can be done using the Start-Job cmdlet with the -RunAs32 switch, however I’m having trouble providing a value for the -ArgumentList parameter.

I came up with the following to search for whichever script parameters have values and build a command line out of them:

function GetValueText([Object] $value)
{
    [String] $text = if ($value -eq $null) {
        '$null';
    } elseif ($value -is [String]) {
        "'$value'";
    } elseif ($value -is [Array]) {
        '@({0})' -f (($value | ForEach-Object { GetValueText $_ }) -join ', ');
    } else {
        "$value";
    }

    return $text;
}

if ([IntPtr]::Size -gt 4)
{
    [String] $scriptPath = $MyInvocation.MyCommand.Path;
    [String[]] $parameters = @(
        $MyInvocation.MyCommand.Parameters.Keys `
        | ForEach-Object {
            [Object] $parameterValue = Get-Variable -Name $_ -ValueOnly;

            if ($parameterValue -ne $null)
            {
                [String] $parameterValueText = GetValueText $parameterValue;

                '-{0}' -f $_;
                $parameterValueText;
            }
        }
    );
    [Object] $job = Start-Job -FilePath $scriptPath -RunAs32 -ArgumentList $parameters;
    [Object[]] $data = $job | Wait-Job | Receive-Job;

    $data;
}
else
{
    # Retrieve data...
}

When it gets to the Start-Job line it generates an error with message "Cannot convert value "-Argument1" to type "System.Int32[]"". -Argument1 is the script’s first parameter and is of type [Int32[]], so does this mean that -ArgumentList only works with positional and not named parameters?

I’ve also tried simplifying it to…

param(
    [String] $stringArg,
    [Int32] $int32Arg
)

$PSBoundParameters;

if ([IntPtr]::Size -gt 4)
{
    [String] $scriptPath = $MyInvocation.MyCommand.Path;
    [Object] $job = Start-Job -FilePath $scriptPath -RunAs32 -ArgumentList @PSBoundParameters;

    $job | Wait-Job | Receive-Job;
}
else
{
    Get-Date;
}

…but when I run .\Test.ps1 'string' 12345 from a 64-bit session, it displays…

Key                                                         Value
---                                                         -----
stringArg                                                   string
int32Arg                                                    12345
Start-Job : Missing an argument for parameter 'ArgumentList'. Specify a parameter of type 'System.Object[]' and try again.
At X:\Test.ps1:11 char:72
+     [Object] $job = Start-Job -FilePath $scriptPath -RunAs32 -ArgumentList <<<<  @PSBoundParameters;
    + CategoryInfo          : InvalidArgument: (:) [Start-Job], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.StartJobCommand

…so @PSBoundParameters seems to evaluate to $null. I’m not sure why this isn’t working or what else to try.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:31:06+00:00Added an answer on June 1, 2026 at 3:31 am

    This is probably going to look a little odd, but:

    param(
    [String] $stringArg,
    [Int32] $int32Arg
    )
    
    if ([IntPtr]::Size -gt 4)
    {
    [String] $scriptPath = $MyInvocation.MyCommand.Path;
    
    $params = @()
    $psboundparameters.keys |
      foreach {
          $params += "-$($_)"
          $params +=  $psboundparameters.$_
          }
    
    
    $sb = [scriptblock]::Create(@"
    &'$scriptpath' $params
    "@)
    
    [Object] $job = Start-Job -scriptblock $sb -RunAs32 
    $job | Wait-Job | Receive-Job;
    }
    else
    {
    Get-Date
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short of putting a UIWebView as the back-most layer in my nib file, how
Short version: How can I get the URL of the server my MVC3 project
Short & Sweet: How can I take the hex input of 28E02 and convert
Short version : How can I drag Link 1 into one of the dropdowns
Short question: How can I use createLink in a Filter? I'm getting error: No
Short version: What kind of escape sequence can one use to search for unicode
Short version : How can an MFC ActiveX control loaded into a web page
Short question: What does an exception's sourceID refer to, and how can I link
Short: how are the keys changed when migrating to HR. Does just the App
Short question: Can anyone tell me what the requirements (especially when it comes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.