?
Solved

Powershell insert sleep command into Powershell foreach script.

Posted on 2008-11-06
5
Medium Priority
?
6,770 Views
Last Modified: 2010-05-18
Please refer to the following code.  In the first line of code, I want to insert a start-sleep command between the get-ftp statement and the foreach-object -process statement.  The idea is to obtain a list of files, but delay the processing for 180 seconds.

How is this completed?

get-ftp -server myserver -user myuser -password mypassword -ssh -force -path /path/to/data/*.csv | foreach-object -process {
get-ftp -server myserver -user myuser -password mypassword -ssh -force -path "/path/to/data/" -remotefile ($_.Filename) -localfile ("C:\path\to\data\" + $_.Filename) 
send-ftp -server myserver -user myuser -password mypassword -ssh -force -path "/path/to/data/" -remotefile ($_.Filename) -rename ("/path/to/data/" + $_.Filename)

Open in new window

0
Comment
Question by:jloomans
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22898658
start-sleep 180
0
 

Author Comment

by:jloomans
ID: 22898719
How is this nested into the first line of code, so I can obtain the list of files to process, sleep 180, then start the processing?
0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 2000 total points
ID: 22898756
oh... try this

get-ftp -server myserver -user myuser -password mypassword -ssh -force -path /path/to/data/*.csv | foreach-object -begin {start-sleep 180} -process {

0
 

Author Comment

by:jloomans
ID: 22899169
Ahh, so simple.  I should've known that.
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22899748
np
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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...
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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

862 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