Hi, Need some help with Invoke-Command and passing variables to a script -Filepath.
I know we can use invoke-command to run a script located on a remote server, and run it ‘locally’.
Something like:
Invoke-Command -ComputerName $Server -FilePath C:\myFolder\myScript.ps1
But how do I pass local variables in my script to that remote script?
I’ve seen plenty of examples using Scriptblock, but I want to pass in parameters to the entire remote script (just like using
Param (
$x,
$y
)
I’ve seen examples like:
$Name = "svchost" $CPU = 99 Invoke-Command –ComputerName $RemoteComputer –ScriptBlock { param($RemoteName,$RemoteCPU) Get-Process -Name $RemoteName | Where -Property CPU -gt $RemoteCPU } -ArgumentList $Name,$CPU
But how do I do the same, but not use scriptBlock, but pass local variables as parameters into the remote script with -Filepath?
Does ArgumentList still work? What is the syntax though?
Invoke-Command - ComputerName $RemoteComputer -Filepath ????
Hope that makes sense?
I will have scripts located on remote servers, but need to pass different variables from time to time.
Thanks for any advice!
Alex.