Speeding up powershell report via jobs?

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 7 years and 1 month 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Speeding up powershell report via jobs?

Post by jvierra »

Use one form or the other but not both:

Either:
  1. $computers = 'computer01'
  2. $sb = {
  3.   Param(
  4.     [string[]]$Computers
  5.   )
  6.    . c:\pathtomyscript\HealthCheck.ps1 #so that I can use .\HealthCheck for?
  7.      Get-ComputerReport -html -All -RunAsJob -ComputerName $computers
  8. }
Or:
  1. $computers = 'computer01'
  2. $sb = {
  3.    . c:\pathtomyscript\HealthCheck.ps1 #so that I can use .\HealthCheck for?
  4.      Get-ComputerReport -html -All -RunAsJob -ComputerName $using:computers
  5. }
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Speeding up powershell report via jobs?

Post by stevens »

Thanks, that works. It also works in the form BUT it doesn't work when I want to make it location independant.
Please advise on that.
  1. Add-JobTracker -Name 'HealthCheck' `
  2.                        -JobScript {
  3.  
  4.             $ScriptPath = Split-Path $MyInvocation.MyCommand.path
  5.             . $($ScriptPath + "HealthCheck.ps1")
  6.             #. FullpathtomyPS1.ps1 works fine
  7.             Get-ComputerReport -All -runasjob -html -ComputerName $Using:ComputerName
  8.            
  9.         }`
  10.                        -CompletedScript {
  11.             Param ($Job)
  12.             $Result = Receive-Job -Job $Job
  13.             Invoke-Item $Result
  14.             #Enable the Button
  15.             $progressbaroverlay1.Visible = $false
  16.             Add-Logs -text "HealthCheck of $ComputerName was done."
  17.             Add-Logs -text "Done"
  18.            
  19.         }`
  20.                        -UpdateScript {
  21.             Param ($Job)
  22.         }`
  23.                        -ArgumentList $null

Also what I still don't get is that the ps1 would get part of the exe. So then you would point to f.e. . e:\pathofmyexe.exe\myps1.ps1 in order to load the ps1?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Speeding up powershell report via jobs?

Post by jvierra »

What means "location dependent"?

Note that you do not need to specify "-argument $null". Just leave off that parameter if you are not using it.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Speeding up powershell report via jobs?

Post by stevens »

I meant location independant => no need to put the full path to the ps1
Now it works with the full path but I want the exe to run anywhere and I never can now where it will be stores so cannot give a hardcoded path.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Speeding up powershell report via jobs?

Post by jvierra »

Your method of finding the script path will not work in a job. A job is not a script.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Speeding up powershell report via jobs?

Post by jvierra »

Just run this line at a prompt to see what is happening:

Start-Job { $MyInvocation } | Wait-Job | Receive-job
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Speeding up powershell report via jobs?

Post by jvierra »

Now run this to see where the job is executing.

Start-Job { $pwd } | Wait-Job | Receive-job
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Speeding up powershell report via jobs?

Post by stevens »

Ok, so there are no options to make my exe run with jobs when I want the exe to run on any location?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Speeding up powershell report via jobs?

Post by stevens »

So using jobs = responsive forms means:
1. lots of extra coding/recoding
2.adding code path hard coded into the project
3.if big functions are needed, adding these functions plain text next to the exe

What a nightmare these jobs and PS Studio. And that's the only way (with these limitations) to make forms more responsive?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Speeding up powershell report via jobs?

Post by jvierra »

You are giving up way too soon.

Now try this:

Start-Job { $args[0] } -Args $pwd | Wait-Job | Receive-job
This topic is 7 years and 1 month 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