0
votes

I wrote this code:

$vmName = $args[0]
$sign_check_tool = $args[1]
$arguments = $args[2]

$remote_session = New-PSSession -VMName $vmName -Credential $cred

try {
Invoke-Command -Session $remote_session -Block {

   $signcheck_output = ./$using:sign_check_tool /accepteula -c $using:arguments

   Write-Output "${signcheck_output }"

}
} catch [Exception] {
    Remove-PSSession $remote_session
    exit 1
}

Exit-PSSession

I want to run this script for several sign check tools that I receive as a parameter, and for different installers. But I get this error:

The term './$using:sign_check_tool' is not recognized as the name of a cmdlet, function,  file, or operable 

I want to pass as a parameter several types of tools to run for the same installer but I get the previous error. If you could help me, I would be grateful.

1
Remote host is supposed to have those tools installed if you want to invoke them. If not you can add code to map network drive and upload executables needed to finish the task. - metablaster
Before calling this code, I copy everything I need on that machine, both the tool which is a simple .exe file, and the file I am testing. - softeng1998

1 Answers

0
votes

I think you need to pass $using:sign_check_tool to -ArgumentList to be picked up, for example:

Invoke-Command -Session $remote_session -Block -ArgumentList $using:sign_check_tool, $using:arguments {
   param($tool, $args)

   $signcheck_output = ./$tool /accepteula -c $args

   Write-Output "${signcheck_output }"

}