After meeting with
marketing department I usually need couple of hours to clean my brain
after their specific terminology. Next script has been born after
just another such meeting as a small revenge :).
Administrators have
small problem, after patching procedure computer normally requires
reboot. But usually we have boomerang effects, users are ignoring
reboot requests, workstations keep working and so on.. Gentlemen, we
need own jingle (grrr...this marketing again).
I implemented next idea,
instead of dry text in message box, I'm showing funny pictures in
window. This is first version of
my powershell script. It basically creates GUI form and add two
element button and picture with request.
And my systems reboot rate
was increased on 60%.
Clear-host
$pictureFile= get-item("C:\temp\005Screen00.jpg")
[void][reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
[void][reflection.assembly]::LoadWithPartialName( "System.Drawing")
$mainForm = New-Object Windows.Forms.Form
$mainForm.AutoSize = $True
$mainForm.AutoSizeMode = "GrowAndShrink"
$mainForm.Text ="PLEASE..."
$formPicture = New-Object Windows.Forms.PictureBox
$picture=[System.Drawing.Image]::Fromfile($pictureFile)
$formPicture.Image = $picture
$formPicture.Width = $picture.Width
$formPicture.Height = $picture.Height+40
$formButton = New-Object Windows.Forms.Button
$formButton.Location=new-object System.Drawing.Size(0,($formPicture.Height-40))
$formButton.Size = new-object System.Drawing.Size($formPicture.Width,40)
$formButton.Text="REBOOT COMPUTER"
$formButton.Add_Click({ Restart-Computer })
$mainForm.Controls.Add($formButton)
$mainForm.controls.Add($formPicture)
$mainForm.ShowDialog()
As a second version of
this approach, nice to have folder with different images,which
randomly showing to user, message is drawing directly to picturebox
instead embedded in picture, more accurate reboot procedure. But this
is homework for you guys. Don't be lazy. As
a small help I have added auto alignment to main window, so you don't
need to care of picture size pre-moderation.
Have
a good evening.
No comments:
Post a Comment