Hi,
I'm using invoke-command to run script code on a remote computer. I have a file with a library of functions I'd like to pass into the remotely executed script, but I'm only getting the first line. The problem is something to do with my ArgumentList but I can't get one that works. Here's what I have
$scr = Get-Content ".\function_lib.ps1"
invoke-command -ComputerName remote-computer -ArgumentList $scr -ScriptBlock {
param ([string]$scr)
invoke-expression -Command $scr
use-function-from-lib -parm1 "parm1"
}
If I write the contents of $scr to a file, all I get is the first line. How can I pass the string representation of the function library to the remote script?
Thanks,
Scott
I finally figured this out. The Get-Content cmdlet was stripping out line breaks, and the parameter cast looks like it was messing something up. Here's the fixed code
$scr = [io.file]::ReadAllText("function_lib.ps1")
param ($scr)