DevSupport
asked on
outfile in current directory of powershell script
How do I put the outfile in the current directory where ps script is located.
I'm trying something like this but doesnt work
$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.De finition
Out-File $PSScriptRoot + '\output1.txt'
ps version 4.
Please help.
Thanks
I'm trying something like this but doesnt work
$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.De
Out-File $PSScriptRoot + '\output1.txt'
ps version 4.
Please help.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This:
Ths works:
Out-File $PSScriptRoot + '\output1.txt'
leads to a run-time error because the + is interpreted as parameter (for encoding).Ths works:
$PSScriptRoot = Split-Path -Path $MyInvocation.MyCommand.Definition
# or
$PSScriptRoot = $MyInvocation.MyCommand.Path.DirectoryName
Out-File ($PSScriptRoot + '\output1.txt')
ASKER