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 »

stevens wrote:Thanks. I'll have look at the form.
Can you clarify what you mean by "Large job scripts should be add to a project as external files and they will be deployed by the installer."
The only thing I would like to avoid is having ps1 files (only for my jobs) next to my exe (which contains my project), is that possible?
You can find instructions on how to use projects in the PSS documentation available on the help page. There are also a number of blog posts describing how to design, build and deploy projects. THe blogs and documentation can describe this better than I can in a short forum post.

Simple to say that a file in a project can be an included file or not and is marked as such via the file "properties" panel. An external file does not get inserted into the generated, single script but remain as associated files.
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 for the form, that makes it much clearer! However, what I don't get is why you add the else{ $filter='*'} because if you add no text, it sounds a bad idea to list all groups in AD. Note also that at the end of the search, the button sticks at an image with a circle in it instead of the normal image.

What you said about files in project, I'll try to figure out what you mean because that's kind of fuzzy.
Since I want to make my form more responsive, I guess jobs are the only way to go. But copying all function into a job, thereby risking to forget to do adaptations to the function when original ones are changed, doesn't seem a good idea.
So then I'd have to import them into the job, ok. Fair enough. But will it appear next to the exported exe I make of the project? If not, great, that's the way I want to go. If yes, I absolutely don't want that.
If not, can't I share these functions with my project, so I have a single place for these functions instead of 2? Please do clarify that, the rest I'll figure out.
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 can change it as you like I just did that so null strings wouldn't throw errors. You need to add validation code.
You should add the functions to the project as a remote file, a module or a project local file. The choice is up to you.
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 »

You should add the functions to the project as a remote file, a module or a project local file.
So that means I can add it a a file into my project in those ways but how do I point to it? In other words, when it would be a module, I could just load-module and the name (without location)?
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 »

If you add a file to a project you can set the properties of the file to make the file an external file but included in the project. The file can then be added to your job by using dot sourcing the same as you would use any file that was a function provider.
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 my function is a healthcheck which launches the result in a browser.
The computername is already loaded in $computername.
I guess I have to load the result differently here, but I do not know how (PS Studio crashes when I run the healthcheck job).

So I have my function in healthcheck and load them in the job.
  1. #$_.SuppressKeyPress = $true
  2.        
  3.         Add-JobTracker -Name 'HealthCheck' `
  4.                        -JobScript {
  5.             #YOU CAN NOT USE CUSTOMSCRIPTS UNLESS YOU DEFINE THEM OR IMPOR THEM
  6.             .\HealthCheck.ps1
  7.             Get-ComputerReport -All -html -ComputerName $Using:ComputerName
  8.            
  9.         }`
  10.                        -CompletedScript {
  11.             Param ($Job)
  12.             $Result = Receive-Job -Job $Job
  13.             #Enable the Button
  14.             $progressbaroverlay1.Visible = $false
  15.            
  16.             #Load-DataGridView -DataGridView $datagridviewGroup -Item $Groups
  17.             #$datagridviewGroup.DataSource = ConvertTo-DataTable -InputObject $Groups
  18.             Add-Logs -text "Done"
  19.            
  20.         }`
  21.                        -UpdateScript {
  22.             Param ($Job)
  23.         }`
  24.                        -ArgumentList $null
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 asking a new question now. I suggest you make this work as a stand alone job. Launching IE from a job running under a form may present issues. First it must work at a prompt then under a CLI job. Then try it in a form.

"Crash" is not a very descriptive diagnostic.
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 »

Made it work as a job.
  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 $using:computers
  8. }
  9.  
  10. Start-Job -Name HealthCheck -ScriptBlock $sb -Args $computers | Wait-Job
  11. $Result = Receive-Job -Name HealthCheck -kee
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 »

But the code makes again my PS Studio crash. Again Exchange module, beats me why it crashed on that.
Error:
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: scriptdriver64.exe
Problem Signature 02: 1.4.42.0
Problem Signature 03: 588075a7
Problem Signature 04: Microsoft.Exchange.Diagnostics
Problem Signature 05: 14.1.218.11
Problem Signature 06: 4c5fa811
Problem Signature 07: 57e
Problem Signature 08: 0
Problem Signature 09: System.NullReferenceException
OS Version: 6.3.9600.2.0.0.16.7
Locale ID: 2067
Additional Information 1: 0e59
Additional Information 2: 0e598d38e80f4208170f1b110e704760
Additional Information 3: 16c2
Additional Information 4: 16c2677c0226fb59d16743196ab0bea6

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=280262

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt


The code:
  1. Add-JobTracker -Name 'HealthCheck' `
  2.                        -JobScript {
  3.             #YOU CAN NOT USE CUSTOMSCRIPTS UNLESS YOU DEFINE THEM OR IMPOR THEM
  4.             .\HealthCheck.ps1
  5.             Get-ComputerReport -All -runasjob -html -ComputerName $Using:ComputerName
  6.            
  7.         }`
  8.                        -CompletedScript {
  9.             Param ($Job)
  10.             $Result = Receive-Job -Job $Job
  11.             Invoke-Item  $Result
  12.             #Enable the Button
  13.             $progressbaroverlay1.Visible = $false
  14.            
  15.             #Load-DataGridView -DataGridView $datagridviewGroup -Item $Groups
  16.             #$datagridviewGroup.DataSource = ConvertTo-DataTable -InputObject $Groups
  17.             Add-Logs -text "Done"
  18.            
  19.         }`
  20.                        -UpdateScript {
  21.             Param ($Job)
  22.         }`
  23.                        -ArgumentList $null
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 »

Also
ERROR: Invoke-Item : Cannot bind argument to parameter 'Path' because it is null.
So the Get-ComputerReport did not work.
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