Need Help with my Output File

by xtree79 at 2013-03-16 05:17:56

Hi everyone,

As you can see below I wrote a sricpt to search for files and put the output into a tex file.

My problem is this, I would like to format my output results like the following:

insert1 + { $.FullName } + insert 2 + { $.FullName } =


Could someone help me with this ?


Here is a copy of my current script:

# PowerShell Foreach-Object
$findDir ="search directory"
$LogPath = "my ouputfolder"
$FilesExe = gci $findDir -recurse
$filetype = "test.txt"
$outFile = $LogPath + $filetype
$insert1 = "decode"
$insert 2= "\output"
# Create Log File Function
$Logs = $FilesExe | ? {$.extension -eq ".zpl"} | foreach { $.FullName } | Out-File $outFile -Append
by DonJ at 2013-03-16 09:10:37
Please use the CODE button to format code.

The format operator may be appropriate.


"{0} {1} {2} {3}" -f $insert1,$.FullName,$insert2,$.FullName


Each {0} placeholder will take the corresponding item from the comma-separated list {0} gets the first item, {1} gets the second, and so on. You can read more in about_operators, I believe.
by xtree79 at 2013-03-16 16:42:01
hey Don,
thanks for the reply, well i tried what you told me above but now I getting a syntax error when i try to run it.
Is there something else i m missing from using the format operator ?
thanks in advance

# PowerShell Foreach-Object
$findDir ="C:\Users\rkirkland\Desktop\Clients"
$LogPath = "C:\Users\rkirkland\Desktop\Clients\powershell1"
$FilesExe = gci $findDir -recurse
$filetype = "test.txt"
$insert1 = "decode"
$insert2 = "\output"
$outFile = $LogPath + $filetype
$Logs1 = $FilesExe | ? {$.extension -eq ".zpl"}| foreach ($Log in $Logs1){
"{0} {1} {2} {3}" -f <br> $insert1,$_&#46;FullName,$insert2,$_&#46;FullName| Out-File $outFile -Append <br> }<br></code></blockquote>by DonJ at 2013-03-16 16:47:08<blockquote>Seeing the error would help.</blockquote>by xtree79 at 2013-03-16 19:32:01<blockquote><code>Unexpected token 'in' in expression or statement&#46;<br>At C&#58;\Users\rkirkland\Desktop\Clients\powershell\findzpl2&#46;ps1&#58;9 char&#58;67<br>+ $Logs1 = $FilesExe | ? {$_&#46;extension -eq &quot;&#46;zpl&quot;}| foreach ($Log in &lt;&lt;&lt;&lt; $Logs1){<br> + CategoryInfo &#58; ParserError&#58; (in&#58;String) &#91;&#93;, ParseException<br> + FullyQualifiedErrorId &#58; UnexpectedToken</code></blockquote>by DonJ at 2013-03-16 19:48:08<blockquote>Ah. Yeah. You're using ForEach-Object wrong. You're using the scripting construct, which is not legal in the pipeline. ForEach-Object, the cmdlet (what you're using) is different from ForEach the scripting construct. It's confusing because ForEach is an alias to the cmdlet and also the scripting construct. <br><br><code><br>letype<br>$FilesExe | ? {$_&#46;extension -eq &quot;&#46;zpl&quot;}| foreach {<br> &quot;{0} {1} {2} {3}&quot; -f
$insert1,$
.FullName,$insert2,$.FullName| Out-File $outFile -Append
}


You were mixing two methods.
by xtree79 at 2013-03-17 08:13:10
Don,

thanks again for your help, by the way i finally got it work for me:

# PowerShell Foreach-Object
$findDir ="C:\Users\rkirkland\Desktop\Clients&quot;
$LogPath = "C:\Users\rkirkland\Desktop\Clients\powershell1&quot;
$FilesExe = gci $findDir -recurse
$filetype = "test.txt"
$insert1 = "decode"
$insert2 = "\output"
$outFile = $LogPath + $filetype

$Logs1 = $FilesExe | ? {$
.extension -eq ".zpl"}
$logs1 = $FilesExe | ? {$.extension -eq ".zpl"}| foreach {
"{0} {1} {2} {3}" -f `
$insert1,$
.FullName,$insert2,$_.FullName| Out-File $outFile -Append
}