1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
[void] [reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$FormMsg = New-Object System.Windows.Forms.Form
$FormMsg.Text = "Outil d'envoi de messages"
$FormMsg.Size = New-Object System.Drawing.Size(300,200)
$FormMsg.StartPosition = "CenterScreen"
$FormMsg.KeyPreview = $True
$FormMsg.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objTextBox.Text;$FormMsg.Close()}})
$FormMsg.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$FormMsg.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objTextBox.Text;$FormMsg.Close()})
$FormMsg.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Annuler"
$CancelButton.Add_Click({$FormMsg.Close()})
$FormMsg.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Message :"
$FormMsg.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$FormMsg.Controls.Add($objTextBox)
$FormMsg.Topmost = $True
$FormMsg.Add_Shown({$FormMsg.Activate()})
[void] $FormMsg.ShowDialog()
$msg = $objTextBox.Text
$computer = Get-ADComputer -Filter * | select Name | where Name -Like "machine*"
$computersession = New-PSSession -ComputerName $computer.Name
Invoke-Command -Session $computersession -ScriptBlock { [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms") }
Invoke-Command -Session $computersession -ScriptBlock { [System.Windows.Forms.MessageBox]::Show($msg,"Information",[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Asterisk)}
Remove-PSSession -ComputerName $computer.Name |
Partager