problem with invoke-expression


  1.    02 Apr 2008 #1
    Ben Christian Guest

    problem with invoke-expression


    trying to open some documents, but some of the filenames have spaces in them,
    and i'm not able to get invoke-expression to properly read it. I've tried
    messing around with quotes, double quotes, parenthesis, etc, but can't seem
    to get it to work...invoke expression stops reading the variable where the
    first space in the path is...

    here's the code snippet...


    $files = @(get-childitem $searchpath | ? {$_.extension -match "pdf"})

    foreach ($document in $files) {
    write-host $document.fullname
    invoke-expression $document.fullname
    }

    i've also just tried using $searchpath\$document instead of
    $document.fullname. Neither work.

    Thanks for your help!!
      My System SpecsSystem Spec

  2.    02 Apr 2008 #2
    Kiron Guest

    Re: problem with invoke-expression


    Use Invoke-Item instead of Invoke-Expresion

    foreach ($document in $files) {
    write-host $document.fullname
    invoke-item $document.fullname
    }

    --
    Kiron
      My System SpecsSystem Spec

  3.    02 Apr 2008 #3
    Kiron Guest

    Re: problem with invoke-expression


    You can also use the Call operator too:

    foreach ($document in $files) {
    write-host $document.fullname
    & $document.fullname
    }

    --
    Kiron
      My System SpecsSystem Spec

  4.    02 Apr 2008 #4
    Kiron Guest

    Re: problem with invoke-expression


    ...or the Dot:

    foreach ($document in $files) {
    write-host $document.fullname
    . $document.fullname
    }

    --
    Kiron
      My System SpecsSystem Spec

  5.    06 Apr 2008 #5
    Keith Hill [MVP] Guest

    Re: problem with invoke-expression


    True but since the primary distinction between & and . (dot) is that dot executes the command in the current scope there isn't much benefit to using it when invoking external commands.

    --
    Keith
    "Kiron" <Kiron@xxxxxx> wrote in message news:41032077-DEBE-4311-BDE6-0E5CB71301F6@xxxxxx
    ...or the Dot:

    foreach ($document in $files) {
    write-host $document.fullname
    . $document.fullname
    }

    --
    Kiron
      My System SpecsSystem Spec

problem with invoke-expression

Similar Threads
Thread Forum
invoke-expression problem
People I'm having a problem making a string from a number of variables (I've simplified the stuff below) then executing it, and have tried a...
PowerShell
Ambersand & Invoke-Expression
I need to use Invoke-Expression on a statement including ambersands & Example: Invoke-Expression "dir c:\ & if errorlevel 1 echo "PANIC!" My...
PowerShell
CTP: Invoke-Expression error
Hi I'm trying to run remote commands on a computer named "spare". Attached the error description. Both machines (source and destination) runs...
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
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,...
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
  • Old server
    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 08:57.
    .