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.
Locked
User avatar
ALD Automotive
Posts: 10
Joined: Wed Feb 07, 2018 10:28 pm

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.  
  3.     FOREACH ($i IN $PCs)
  4.  
  5.     {
  6.  
  7.         $pc = $i.Cells["ComputerName"].Value
  8.  
  9.         $start_time = $i.Cells["StartTime"]
  10.  
  11.         Restart-Computer $pc -Force
  12.  
  13.         Start-Job -ScriptBlock {
  14.  
  15.             FOR ($t -ne 1)
  16.  
  17.             {
  18.  
  19.                 IF (Test-Connection $args[0] -Quiet -eq $false)
  20.  
  21.                 {
  22.  
  23.                     $args[1].Value = "$(Get-Date -Format "HH:mm")"
  24.  
  25.                     $t = 1
  26.  
  27.                 }
  28.  
  29.             }
  30.  
  31.         } -ArgumentList $pc, $start_time
  32.  
  33. }
What i do wrong?
Attachments
Grid.jpg
Grid.jpg (174.54 KiB) Viewed 235 times

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 10
Joined: Wed Feb 07, 2018 10:28 pm

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.             {
  4.  
  5.                 IF ((Test-Connection $pc -Quiet) -eq $false)
  6.  
  7.                 {
  8.  
  9.                     $Start_Time.Value = "$(Get-Date -Format "HH:mm")"
  10.  
  11.                     $t = 1
  12.  
  13.                 }
  14.  
  15.             }
Works correctly, but all form waiting then "For" will end.

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: DataGridView

Post by jvierra »

You have to restart the computer with "-wait". It will tell you when the PC has finished its restart.

Locked