Shell – passing value from powershell script to cmd script

command linepowershell

I want to pass value “200001” from the PowerShell to cmd script “1%”
The cmd script used by multiple powershell scripts, and each PowerShell script has its own value.

PS script:

function CallcmdExtract
{
$var_cmd=  "D:\ cmd\Generatefile.cmd"
    $Invocation = (Get-Variable MyInvocation -Scope 1).Value
    $ScriptPath = Split-Path $Invocation.MyCommand.Path
try {
Invoke-Item $var_cmd 
    }
catch {
    throw("ERROR: Problem encountered, error=$_")
    }
}
CallcmdExtract

The cmd script that I want to pass the value to it is

@echo off
IF (%1) == () GOTO EXIT_ERROR
SET CLIENT=%1
.
.
.

Best Answer

i have solved the problem using

  • $Value_you_want_to_pass = XXXXXX
  • Invoke-command -ScriptBlock {& $cmdpath $Value_you_want_to_pass}
Related Question