1

ConsoleApplication:

class Program
{
    static void Main()
    {
        using (var runSpace = RunspaceFactory.CreateRunspace())
        {
            runSpace.Open();
            runSpace.SessionStateProxy.SetVariable("Var1", "Alex");
            using (var pipeline = runSpace.CreatePipeline("C:\\P.ps1"))
            {
                pipeline.Invoke();
            }
        }
    }
}

P.ps1

$logFile = "C:\MyLog.txt"

function Write-Log ([string] $message)
{
    Add-Content -Path $logFile -Value $message
}

Write-Log "Var1: " + $Var1

I expect "Var1: Alex" is written into my log file, but I get "Var1: ".

What did I wrong?

Edit:

My original problem is on the following site: http://nugetter.codeplex.com/workitem/31555

Rookian
  • 19,841
  • 28
  • 110
  • 180

1 Answers1

4

Because of the space in write-log it sees them as multiple parameters.

Try this

Write-Log "Var1: $Var1"
Christian Specht
  • 35,843
  • 15
  • 128
  • 182
BSonPosh
  • 56
  • 1