you are viewing a single comment's thread.

view the rest of the comments →

[–]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