Showing posts with label start-sleep. Show all posts
Showing posts with label start-sleep. Show all posts

Friday, May 9, 2014

Everyday Powershell - Part 20 - Rollback system time and launch a program

So there are times where loading an older application requires you to rollback the date of your system. Our UPS management console has had this odd requirement since 2014. So we threw this together to make life a little easier;

set-date 01/01/2009
Start-Process "c:\windows\system32\notepad.exe"
Start-sleep 15
set-date (invoke-command -ComputerName SOMECURRENTTIMESERVER -ScriptBlock {get-date})

You can update the process path in the second line, then save this as a .ps1 file and use it as a shortcut to launch time-bombed applications.

It does require the appropriate permissions on the sever we get the time from in the fourth line. It'll also need Powershell Remoting enabled.

Wednesday, November 13, 2013

Everyday Powershell - Part 8 - Powershell Slideshow

This is the next part in an ongoing series about Powershell. You may have heard about how awesome Powershell is but have struggled to find ways to make it useful in your day to day work. That's what this series is going to address. It'll provide scripts and knowledge to address practical everyday problems

First let me congratulate you finding this article! Especially if you came via Google. Finding a blog post on "Powershell Slideshows" among all the "Powerpoint" slideshows would have been an interesting challenge!

Let's say you wanted a PC to boot up and show a slideshow of images in a given folder. Do you think that you'd need some third party software? Could windows photo viewer do it? A colleague of mine was about to create a video in Windows Movie Maker before I asked...

"Why don't we try POWERSHELL?"

$folder = "C:\Users\someuser\Documents\Pictures\"
$wait = 1

[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$form = new-object Windows.Forms.Form
$form.Text = "Image Viewer"
$form.WindowState= "Maximized"
$form.controlbox = $false
$form.formborderstyle = "0"
$form.BackColor = [System.Drawing.Color]::black

$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.dock = "fill"
$pictureBox.sizemode = 4
$form.controls.add($pictureBox)
$form.Add_Shown( { $form.Activate()} )
$form.Show()

do
{
    $files = (get-childitem $folder | where { ! $_.PSIsContainer})
    foreach ($file in $files)
    {
        $pictureBox.Image = [System.Drawing.Image]::Fromfile($file.fullname)
        Start-Sleep -Seconds $wait
        $form.bringtofront()
    }
}
While ($running -ne 1)

Most of this was pinched from here;

Our contribution is the fact it's Fullscreen and the Do While loop. Those clever observers among us will notice the $running will never equal 1 so that do loop is infinite. Which suits our purpose just fine.

What started as a way to settle an argument with a colleague (about the usefulness of powershell in media rich environments) became a great way to demo the windows.forms objects!

Beware though it is a bit of mess from a UI perspective. You can't quit the form once it's shown, you can alt tab and kill it from task manager when you need to close it. It suits what we need because it's just for a PC that boots up and runs a slide show, then shuts down at night. The users won't have to ever touch this PC. This is not something I'd give to end users to interact with. But it's fine for our purposes.