PowerShell: Start all VMWare services, self elevate to admin

For reasons, all my VMWare services are set to manual startup.  I like it this way.

I wanted an easy way to start all the services so naturally, a PowerShell script was required.  However the services can’t be started by PowerShell without elevated privileges, and I usually work in a non-elevated ISE.  So this version of the script self-elevates, saving me precious seconds.

 

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

PowerShell: JIRA Archiver v3

This web scraper is a little odd because it had to run within a very constrained environment.

Essentially it attempts to load URLs consisting of a prefix and sequential numerical suffix in the format;

https://url/browse/JIRA-number

then prints the webpage to PDF via the default printer, and downloads a zip file from the URL found in each page’s ‘aszip’ element.

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

PowerShell: some simple snippets

Some simple PowerShell snippets I find useful.

Not worthy of their own pages, but useful nevertheless.

Show the start time of process

Search inside a set of files for a string

 

 

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

PowerShell: RoboClicky V2 Mouse Move, Click, Screen Capture

This script does a few things.  I will break it apart into separate posts that deal with each bit, but for now here is the whole lot.

The purpose of this script is to;

  • move the mouse to specific screen coordinates
  • click mouse buttons at those coordinates in order to drive an application
  • give the application time to respond
  • take a screenshot
  • save the screenshot as required
  • cater for multiple screens in a horizontal configuration

There are some functions in this one not specifically related to the objectives, but for reasons I won’t go into here, I generally try to keep all scripts as self-contained as possible.  I will try to break this out when I get time.

 

 

 

 

 

 

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

PowerShell: DVD copy automation script V2.0

Requirement

I have a bunch of DVD’s that I want to archive to hard-disk so I can dispose of the DVDs.

Automate the process as much as possible.

Note: This is not a DVD copy protection crack, the DVD’s have to be copyable by the OS.

Synopsis

This script will wait for the DVD volume name to be NOT NULL

When a DVD is inserted, the script automatically creates a new folder in the destination root path, using the DVD name as the destination folder name.

After completing the copy it ejects the DVD drive and loops back into the waiting state.

Features

  • Disk insertion detection (not based on auto-run)
  • Destination folder name duplication protection via folder-name suffix (this prevents DVDs of the same name overwriting each-other)
  • Simple copy integrity check using source and destination length comparison
  • Speech so I can hear it from the next room when the DVD needs to be changed out

To Do

I’m wondering if using  [System.IO.StreamWriter would be faster, but I think the bottleneck would be in the DVD Read, not the disk write.  Speculation only.  Next time I use the script I’ll make that modification and see how it goes.

Disclaimer

My scripts are open source, free to use, come with neither warranty as to optimal performance nor suggestion that they are necessarily the best way to achieve anything.

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

PowerShell Persistent eMail Sender – PixSeeMailR

The Problem

I have a number of scheduled PowerShell scripts that perform various system health checks.  If any of them detect something is amiss they send an alert email to myself and my support group using the send-mailmessage cmdlet.

However if the mail server was inaccessible when attempting to send-mailmessage, the command and resulting alert messages would fail.  This was a probable scenario given that the purpose of the error checking scripts is to detect problems including the inaccessibility of network resources.

So I wanted to easily add a level of persistence to the error message emails without having to require the individual health check scripts run continuously.

My solution was to have the checking scrpits place email details into an xml file, and have a batch emailing script pickup and send those messages when it could connect to the mail server.

Constraints

I considered installing a local SMTP mail server such as hMail, and just let it relay through the corporate SMTP server.  However;

  1. I didn’t want to introduce new software to the server, and even though hMail is relatively simple, even it is seems like overkill for the requirement.
  2. I didn’t think the corporate security guys would appreciate me installing an SMTP server on the network.
  3. Most importantly, I felt like stretching my brain doing some PowerShell problem solving.

So I thought a PowerShell only solution would  be nice.

The Solution

Rather than have all my PowerShell scripts handle emailing I decided to create a simple email handling script I called PixSeeMailR.  (The name makes sense to me in the suite of scripts for which it is used.  See my article PixSeeLog: Error detection through image pixel inspection.)

The various other monitoring scripts create email messages (PowerShell objects that contain all the relevant message parameters) and deposit them into an “Out-Mail” folder as an XML file.

Messages in the Out-Mail folder are processed by PixSeeMailR periodically and moved to a “Sent-Mail” folder when they have been processed.  If the message processing fails for any number of reasons, the messages remain in the Out-Mail folder to be processed in the next period.

This solution design uses a scheduled PowerShell script to check for messages.  I also did consider using the System.IO.FileSystemWatcher to trigger the processing of messages as soon as they were deposited into the Out-Mail folder.  That would require the script to run persistently however and for this exercise I wanted to rely on scheduled script execution.

The following diagram shows how the process will work.

PowerShell Persistent Email Sender

Step 1 – Create Message

The first part of the solution is to create messages.

The following code creates message files by storing all the email message parameters into a PowerShell object and exporting that object to an XML file with Export-Clixml.

I use a message naming convention that guarantees (probably) unique message names.

This Create Message code can be added to any PowerShell script and activated according to whatever criteria is relevant.

Step 2 – Check For and Send Messages

The following code is designed to be run as a scheduled task.  I run it every 60 seconds, but you could run it at whatever frequency you like.

  1. The code performs the following steps:
  2. Check if there are any emails to send
  3. Check if the mail server is accessible
  4. Attempt to send each email
  5. Move sent emails to the ‘Sent’ folder
  6. Any messages that were unable to send successfully remain in the ‘Out’ folder and have their Attempts attribute incremented.

 

Limitations

The solution presented here relies on two success testing methods.

1 – A simple TestNet-Connection against the target SMTP server.  If the server is not available the messages don’t attempt to send.

2 – The success or failure of the Send-MailMessage cmdlet.  If the cmdlet returns any error, the message is flagged for retry.

This approach doesn’t guarantee that the messages will reach the intended recipient, only that the SMTP server accepted the messages without error.

Future Upgrade Ideas

Next, I would like to implement the following upgrades;

  1. Turn the PixSeeMailR into a Windows service.
  2. Consider using System.IO.FileSystemWatcher to trigger mail sends immediately.

Addendum

PixSeeMailR has been running on several of my servers for the past few days and seems to be working well.  I have scheduled a daily test message drop for 10 am every day and so far they have been processed as expected.

The average run time when there are no messages is 00.025 seconds.

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail