Running a script for allotted amount of time or needed data.

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Running a script for allotted amount of time or needed data.

Post by sekou2331 »

Hi,

I have a script that collects data. I want it to run till I either kill it or until a certain amount of data is collected. I know there is something called measure-command. Does it have the ability to break when a certain amount of data is met?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Running a script for allotted amount of time or needed data.

Post by jvierra »

help measure-command -full

The result is no.
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Running a script for allotted amount of time or needed data.

Post by sekou2331 »

Ok how would I go about doing what I originally asked.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Running a script for allotted amount of time or needed data.

Post by jvierra »

You would have to write a script that can do what you ask. There is no command that does that.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Running a script for allotted amount of time or needed data.

Post by jvierra »

Here is one thing you can do:

start-job {dir c:\ -Recurse } | Wait-Job -Timeout 10
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Running a script for allotted amount of time or needed data.

Post by sekou2331 »

How would i collect the data into a file. I tried the below but the file doesn't appear.

Code: Select all

start-job {gci c:\ -Recurse | Set-Content .\outtext.txt} | Wait-Job -Timeout 10
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Running a script for allotted amount of time or needed data.

Post by jvierra »

help about_jobs

Follow the instructions.
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Running a script for allotted amount of time or needed data.

Post by sekou2331 »

Looking into it looks like it doesn't work. It creates the file but there is no data in file. Also reading about jobs the wait option brings back the terminal but job is still running.

Code: Select all

$job = Start-Job -ScriptBlock { Get-Process }
Receive-Job -Job $job | Out-File results.txt
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Running a script for allotted amount of time or needed data.

Post by jvierra »

Code: Select all

$job = Start-Job -ScriptBlock { Get-Process } 
$job | Wait-Job | Receive-Job  | Out-File results.txt
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked