invoke-expression not appending


  1.    29 Jun 2007 #1
    Frank Guest

    invoke-expression not appending


    Hi,

    I have a situation where when I use invoke-expression, I cannot output to a
    file. It just outputs to the console but when I run the command, it does
    output to a file. I pipe the output to out-file filename -append. , ie.

    $testfile= file.txt
    $cmd = "rmtshare \\testserver\share1"
    invoke-expression $cmd | out-file $testfile -append


    although it works when I do:

    $testfile = file.txt
    rmtshare \\testserver\share1 | out-file $testfile -append

    Can someone explain this?

    Thanks in advance,






      My System SpecsSystem Spec

  2.    29 Jun 2007 #2
    Brandon Shell Guest

    Re: invoke-expression not appending


    it works for me, but I had to qualify the path to rmtshare.exe

    PS> $testfile = "c:\temp\testfile.txt"
    PS> $cmd = ".\rmtshare.exe \\localhost\download"
    PS> Invoke-Expression $cmd | out-File $testfile -append
    PS> gc $testfile
    Share name \\localhost\download
    Path C:\download
    Remark
    Maximum users No limit
    Users 0
    Permissions:
    Vista64LT\ndis : FULL CONTROL
    \Everyone : READ
    The command completed successfully.
    Share name \\localhost\download
    Path C:\download
    Remark
    Maximum users No limit
    Users 0
    Permissions:
    Vista64LT\ndis : FULL CONTROL
    \Everyone : READ
    The command completed successfully.

    "Frank" <Frank@discussions.microsoft.com> wrote in message
    news:4D973EAC-75E1-4080-B3DC-3AA854AC992D@microsoft.com...
    > Hi,
    >
    > I have a situation where when I use invoke-expression, I cannot output to
    > a
    > file. It just outputs to the console but when I run the command, it does
    > output to a file. I pipe the output to out-file filename -append. , ie.
    >
    > $testfile= file.txt
    > $cmd = "rmtshare \\testserver\share1"
    > invoke-expression $cmd | out-file $testfile -append
    >
    >
    > although it works when I do:
    >
    > $testfile = file.txt
    > rmtshare \\testserver\share1 | out-file $testfile -append
    >
    > Can someone explain this?
    >
    > Thanks in advance,
    >
    >
    >
    >
    >
    >


      My System SpecsSystem Spec

  3.    29 Jun 2007 #3
    dreeschkind Guest

    RE: invoke-expression not appending


    This might be a bug. It has nothing to do with Out-File. The problem seems to
    be Invoke-Expression or the way that output from legacy applications is
    written to the pipeline. However, I think I found a workaround that should
    work for you.
    You should be able to assign the output of Invoke-Expression (iex) to a
    local variable.
    You can then pipe that variable to Out-Fil etc.

    Here is a simple example:

    PS> $cmd = 'cmd.exe /C echo strange'

    PS> iex $cmd | %{ "Invoke-Expression should write >>$_<< to the pipeline!"}
    strange

    PS> $text = iex $cmd; $text | %{ "Invoke-Expression should write >>$_<< to
    the pipeline!"}
    Invoke-Expression should write >>strange<< to the pipeline!

    --
    greetings
    dreeschkind


    "Frank" wrote:

    > Hi,
    >
    > I have a situation where when I use invoke-expression, I cannot output to a
    > file. It just outputs to the console but when I run the command, it does
    > output to a file. I pipe the output to out-file filename -append. , ie.
    >
    > $testfile= file.txt
    > $cmd = "rmtshare \\testserver\share1"
    > invoke-expression $cmd | out-file $testfile -append
    >
    >
    > although it works when I do:
    >
    > $testfile = file.txt
    > rmtshare \\testserver\share1 | out-file $testfile -append
    >
    > Can someone explain this?
    >
    > Thanks in advance,
    >
    >
    >
    >
    >
    >

      My System SpecsSystem Spec

  4.    30 Jun 2007 #4
    dreeschkind Guest

    RE: invoke-expression not appending


    Another workaround is using parenthesis:

    PS> $cmd = 'cmd.exe /C echo strange'
    PS> (iex $cmd) | %{ "Invoke-Expression should write >>$_<< to the pipeline!"}
    Invoke-Expression should write >>strange<< to the pipeline!

    --
    greetings
    dreeschkind

    "dreeschkind" wrote:

    > This might be a bug. It has nothing to do with Out-File. The problem seems to
    > be Invoke-Expression or the way that output from legacy applications is
    > written to the pipeline. However, I think I found a workaround that should
    > work for you.
    > You should be able to assign the output of Invoke-Expression (iex) to a
    > local variable.
    > You can then pipe that variable to Out-Fil etc.
    >
    > Here is a simple example:
    >
    > PS> $cmd = 'cmd.exe /C echo strange'
    >
    > PS> iex $cmd | %{ "Invoke-Expression should write >>$_<< to the pipeline!"}
    > strange
    >
    > PS> $text = iex $cmd; $text | %{ "Invoke-Expression should write >>$_<< to
    > the pipeline!"}
    > Invoke-Expression should write >>strange<< to the pipeline!
    >
    > --
    > greetings
    > dreeschkind
    >
    >
    > "Frank" wrote:
    >
    > > Hi,
    > >
    > > I have a situation where when I use invoke-expression, I cannot output to a
    > > file. It just outputs to the console but when I run the command, it does
    > > output to a file. I pipe the output to out-file filename -append. , ie.
    > >
    > > $testfile= file.txt
    > > $cmd = "rmtshare \\testserver\share1"
    > > invoke-expression $cmd | out-file $testfile -append
    > >
    > >
    > > although it works when I do:
    > >
    > > $testfile = file.txt
    > > rmtshare \\testserver\share1 | out-file $testfile -append
    > >
    > > Can someone explain this?
    > >
    > > Thanks in advance,
    > >
    > >
    > >
    > >
    > >
    > >

      My System SpecsSystem Spec

invoke-expression not appending

Similar Threads
Thread Forum
Invoke-Expression Blues.
Hi, I'm using Powershell to generate MBSAcli scan strings. Been working great forever, till today! Turns out that a username on a particular...
PowerShell
invoke-expression -computername ...
Does the Windows Firewall service have to be running in order to use WS-Management? I really like this remoting capability, however, all of our...
PowerShell
Invoke-Expression issue
I'm trying to run a command against a remote machine using ivnoke-expression. The remote machine is Windows 2003 SP2 with winrm and powershell v1.0...
PowerShell
Possible invoke-expression issue?
I found an issue while i'm creating an backup script. In this script i want to invoke an windows packer from an script based on various parameters....
PowerShell
Invoke-expression vs &
What's the difference? For example, $t='notepad c:\temp\x.txt' &$t # this fails invoke-expression $t #this works More generally, I'm...
PowerShell
Invoke-expression help for logparser
Hi, I have been using logparser in windows command prompt. I thought to simplify my logparser scripts using powershell, But I have not been able...
PowerShell
Issue: Invoke-Expression with $args in the expression
The following result of Invoke-Expression with $args in the expression seems unexpected: CODE: function fn1 { Write-Host fn1:, $($args +...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 12:31.
    .