Archive for the ‘Powershell’ Category.

Prompt a User for Input In Powershell

Occasionally it is necessary to prompt a user for input in a Powershell script. In my case I just need to remind the user to do something, but the same command can get the user input and store it in a variable.

$input=read-host "Hey user, enter some text!"

The text that enters in the above example is save in the $input variable.

Automate Website Visits With Powershell and Internet Explorer

For my research I found the need to automatically visit a webpage to run a setup and a teardown script. Turns out that it is fairly easy to do. The script is included below.

#cd to Internet Explorer
cd "C:\Program Files\Internet Explorer"
#point ie to the teardown script
./iexplore.exe 10.0.0.20/teardown.php
#sleep for one second - this is needed so IE has a chance to start before it is killed
sleep 1
#kill the internet explorer process
get-process iexplore | stop-process

Background Jobs In Powershell

I have been doing a lot of powershell scripting for my senior thesis. I had the need to run a background job and did not find helpful information through searching Google so I figured I would post this.

Powershell 2 support running scripts in the background with a simple command. The only caveat is that it will only run other powershell scripts.

Start a background job: $job=start-job “script.ps1″

Wait for the job to finish: wait-job($job)