DataGridView

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 3 years and 11 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
ALD Automotive
Posts: 11
Last visit: Thu Jun 01, 2023 4:52 am

DataGridView

Post by ALD Automotive »

Product, version and build:Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.159
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.16299.0
_________________________________________
Good morning.
I make DataGridVew as in attachment. I want, if i select checkbox and after press Restart button, selected servers will be restart and information about time of lost ping will be fill at cell Start time (as job).
What i did:
  1.     $PCs = $datagridviewResults.Rows | Where-Object { $_.Cells["Restart\Shutdown"].Value -eq "Yes" }  
  2.     FOREACH ($i IN $PCs)
  3.     {
  4.         $pc = $i.Cells["ComputerName"].Value
  5.         $start_time = $i.Cells["StartTime"]
  6.         Restart-Computer $pc -Force
  7.         Start-Job -ScriptBlock {
  8.             FOR ($t -ne 1)
  9.             {
  10.                 IF (Test-Connection $args[0] -Quiet -eq $false)
  11.                 {
  12.                     $args[1].Value = "$(Get-Date -Format "HH:mm")"
  13.                     $t = 1
  14.                 }
  15.             }
  16.         } -ArgumentList $pc, $start_time
  17. }
What i do wrong?
Attachments
Grid.jpg
Grid.jpg (174.54 KiB) Viewed 1062 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: DataGridView

Post by jvierra »

What is it that yu ae having an issue with? Is there an error message? Please supply more complete information.
User avatar
ALD Automotive
Posts: 11
Last visit: Thu Jun 01, 2023 4:52 am

Re: DataGridView

Post by ALD Automotive »

Hello,
No error, and not value at cell Start_time.
If i do not use job, but simple type:

$i.cells["start_time"].Value = "$(Get-Date -Format "HH:mm")"
Cell "Start Time" correct fill time. But this is not time lost ping. This is time at press button restart.
If i use all block without job:
  1.              FOR ($t -ne 1)
  2.             {
  3.                 IF ((Test-Connection $pc -Quiet) -eq $false)
  4.                 {
  5.                     $Start_Time.Value = "$(Get-Date -Format "HH:mm")"
  6.                     $t = 1
  7.                 }
  8.             }
Works correctly, but all form waiting then "For" will end.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: DataGridView

Post by jvierra »

You have to restart the computer with "-wait". It will tell you when the PC has finished its restart.
This topic is 3 years and 11 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