[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Explain how this works

Posted on 2014-01-07
4
Medium Priority
?
304 Views
Last Modified: 2014-01-08
Someone gave me this recursive code, but it would fail with this error message:
"Program 'JPEGtoPDF.exe' failed to run: Not enough quota is available to process this command"
I Googled and it seemed to say I was out of resources, but I am not even close, so I decided to watch the program work. I figured out "gci" stood for Get-ChildItem and I started off inserting a SLEEP(1) after the jpegtopdf.exe line. This was painfully slow and only one filename was processed between sleep(1).
I then used the FOR loops to slow it down, but to my surprise it allowed jpegtopdf.exe to process the entire directory it was in and then pausing a moment before doing the next directory\subfolder.
I figure this has something to do with SLEEP(1) stopping the whole program, while the FOR loops allow the executable to run to a certain point and then spit out the results?
What do you think?
Also, is there a web page that can explain how this program works so that I can learn how to do this on my own? I see the %{ after the pipe a lot and then the $(${_.objectname, but I don't know how it works or where to start looking. I Googled, but did not find anything for beginners.
thanks!


$search = "C:\photos"
Get-ChildItem $search -filter *.jpg -Recurse | %{
    write-host "Begin work on :" $_.FullName
    jpegtopdf.exe "$($_.DirectoryName)\$($_.BaseName).PDF" $_.FullName
    #slow it down with FOR loops works.
    #SLEEP(1) pauses for each filename
    for($i=0;$i -lt 1000;$i++)
    {
    for($o=0;$o -lt 100;$o++){}
    }
 }
0
Comment
Question by:johnj_01201
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39763095
Conversion programs tend to eat up the memory. Have you tried increasing the paging file?
0
 
LVL 1

Author Comment

by:johnj_01201
ID: 39763114
Yes, the issue turned out to be the Remote Powershell Window. The program runs fine, 1 file at a time and without the FOR loops, when run on the local server.
I found 1 comment in Google that told there's a limit on Windows Messages and if you fill it up it trips a wire causing this error so that it does not overflow.
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39763429
| % is shortcut for foreach. $_ is self

Your script translates to:
$search = "C:\photos"
$results = Get-ChildItem $search -filter *.jpg -Recurse
foreach ($result in $results) {
     write-host "Begin work on :" + $result.FullName
    jpegtopdf.exe $result.DirectoryName + "\" + $result.BaseName + ".PDF" $result.FullName
}

Open in new window


HTH,
Dan
0
 
LVL 1

Author Closing Comment

by:johnj_01201
ID: 39765035
THANK YOU!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question