0

Trying to write to a file and did the following:

$obj = New-Object System.IO.StreamWriter -ArgumentList join-path $pwd foo.txt

This threw an error

PS C:\code\misc> $obj = New-Object System.IO.StreamWriter -ArgumentList Join-Path $pwd foo.txt
New-Object : A positional parameter cannot be found that accepts argument 'C:\code\misc'.
At line:1 char:18
+ $obj = New-Object <<<<  System.IO.StreamWriter -ArgumentList Join-Path $pwd foo.txt
    + CategoryInfo          : InvalidArgument: (:) [New-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

So am I forced to use a variable for the join-path part? I know I could use [System.IO.Path]::Combine() but I just wanted an alternative to that...

deostroll
  • 11,661
  • 21
  • 90
  • 161

1 Answers1

1

Parenthesis around the Join-Path bit should do the trick.

$obj = New-Object System.IO.StreamWriter -ArgumentList (join-path $pwd foo.txt)
notjustme
  • 2,376
  • 2
  • 20
  • 27