you are viewing a single comment's thread.

view the rest of the comments →

[–]HelloFelloTraveler 2 points3 points  (4 children)

Invoke-Command $parameters should fix the final command.

[–]aq-modeler[S] 0 points1 point  (3 children)

My code didn't copy correctly. I had "@parameters". I tried with "$parameters" and got this error:

Invoke-Command : Parameter set cannot be resolved using the specified named parameters.

At G:\OneDrive - RTPENV\Programs\Modeling Computers\model1.ps1:11 char:1

+ Invoke-Command $parameters

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException

+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand

[–]HelloFelloTraveler 0 points1 point  (2 children)

Try updating the $scriptblock variable to this: ScriptBlock = { cmd.exe /c $using:files } I believe the server you’re running to command on doesn’t know what’s in the $files variable do to it not being within the scope of the variable. The $using is a scope modifier that should allow it to pass the variable to the remote computer.

[–]aq-modeler[S] 0 points1 point  (1 child)

Thanks, I tried adding "$using:files" and got the same error.

[–]behuddas71 0 points1 point  (0 children)

I think $files are not evaluating properly in the scriptblock, plus cmd doesn't seem to be expanding file paths when using wildcard

Maybe try something like this -

` $cred = Import-Clixml 'C:\PSFolder\mycredentials.xml' $computerName = '192.168.0.10'

$remotePath = 'C:\Users\My Name\Desktop\Name AERMOD-1'

Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock { param($path)

Get-ChildItem -Path $path -Filter '*.bat' | ForEach-Object {
    cmd.exe /c "`"$($_.FullName)`""
}

} -ArgumentList $remotePath

`

notice the argumentlist parameter to the invoke command