Powershell: Automated Weekly Status Reports

This is a pretty simple Powershell script that generates a random weekly status report and emails it. I wrote this script because it is important that I produce a weekly status report at my place of employment. The report is graded based on if it was submitted at all and secondly if it was submitted on time. As far as I know nobody actually reads these silly things as the process of checking them is automated. So if the “checker” is automated why shouldn’t the “reporter” be automated? The script is executed via a Scheduled Task.

Here is the script.

#
# Cobbled together by Don
#
# Lazy weekly reports
#

# Set the possible weekly activities
$wrkItems = @("Activity 1",
"Activity 2",
"Activity 3",
"Activity 4",
"Activity 5",
"Activity 6",
"Activity 7",
"Activity 8",
"Activity 9",
"Activity 10",
"Activity 11",
"Activity 12"
)

# Create the email body using three random elements
$outData = "My activities for the week may include but are not limited to:`n`n"
foreach ($ele in get-random -input 0,1,2,3,4,5,6,7,8,9,10,11 -count 3) {
$outData += " - "
$outData += $wrkItems[$ele]
$outData += "`n"
}

# Email the weekly report to the appropriate email address
$SMTPserver = "mail.yours.com"
$from = "don@nowhere.com"
$to = "WeeklyReports@nowhere.com"
$subject = "Don's Weekly Status Report"
$emailbody = $outData
$mailer = new-object Net.Mail.SMTPclient($SMTPserver)
$msg = new-object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
$msg.IsBodyHTML = $false
$mailer.send($msg)

My .docx file opens as a .zip in Outlook Web Access – WTF?

TF is that Exchange 2003 doesn’t know about these new-fangled file extensions so it looks at the headers and sees that they are zip-compressed and assumes they are ZIP files… We just need to add the proper MIME types to Exchange which will in turn set up the attachment properly in OWA.

  1. Open Exchange System Manager
  2. Open the Global Settings branch
  3. Right-click on Internet Message Formats and choose Properties. This brings up the current list of known MIME-types.
  4. Click the Add button. Add the MIME type descriptions (application/vnd.openxmlformats-officedocument.presentationml.presentation) below into the first textbox, and then enter the extension (pptx) in the other textbox.
  5. Click OK and get out of all the dialogs, close ESM.
  6. When you’ve added all 8 of the new MIME-types, restart the Microsoft Exchange Information Store service.

MIME-types:

  • application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
  • application/vnd.openxmlformats-officedocument.presentationml.slide sldx
  • application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
  • application/vnd.openxmlformats-officedocument.presentationml.template potx
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
  • application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
  • application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx

After doing this on the server side, close and re-open Internet Explorer and re-login to OWA.  I cleared my cache in between just to be on the safe side and now .docx files download properly.  Yay!

FWIW, when searching for this solution I found a number of people suggesting that these MIME-types needed to be set up in IIS.  They were already there on my system, just not in ESM.  Also, there is this KB article about opening documents in or not in IE here: http://support.microsoft.com/kb/162059 if that is part of your problem.  Just sayin’.

Make Windows Server 2003 use external NNTP servers in just a few steps:

[vc_row][vc_column][vc_column_text]For future reference, running these commands in a shell is much faster than trying to follow Microsoft’s Knowledge Base instructions (http://support.microsoft.com/kb/816042).

C:> w32tm /config /manualpeerlist:"0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org",0x8 /syncfromflags:MANUAL
C:> w32tm /config /update
C:> net stop w32time
C:> net start w32time
C:> w32tm /resync /nowait

Thanks to Dave Nickason who posted this in 2008 to the Microsoft Forums![/vc_column_text][/vc_column][/vc_row]

VMware Performance Tuning : Disabling System Restore in Windows Guests

Snapshots are available with VMware Workstation, VMware Fusion, VMware Server and ESX/ESXi.

Windows has a feature called system restore.  The idea behind System Restore is to revert to a point in history in case something goes wrong – i.e.: patch Tuesday. It’s an undo feature for your Windows OS. There is overhead for this undo feature, especially on the IO front which is generally acceptable for a dedicated desktop but not ideal for VMs.

One can approximate the function of System Restore with snapshots. Snapshots should be used only when modifying a VM, i.e. patch Tuesday, new software, etc… The idea is “I know I’m making a change so I snapshot the VM”, I execute the change, and test. Once testing reveals no issues and everything works as expected, the snapshot is removed.  (Of course this is now a manual process instead of an auto magic one so it’s a compromise)

Snapshots should not be persistent! They should only have a life of a few hours to a few days.  It is important to remove the snapshots since it creates a delta VMDK file and can grow quite large.  Also, if one creates many snapshots this can affect performance of the guest.

Personally I usually snapshot when the guest is powered down – this gives me the cleanest possible snapshot and I can revert to it with confidence.   It also means the snapshot is created instantly since the file system does not need to be quiesced.  Additionally, it is important to remember your VMware hypervisor can quiesce the file system (so long as VMware tools installed) but not necessarily the applications running in Windows.  i.e.:  SQL cannot be snapshotted reliably.

It is also very important to remember Snapshots are not backups in anyway shape or form. For “backup” purposes the entire VM package should be copied and compressed and stored on a medium other that the host running the VM.  i.e.:  I store my VM archives on my DIY NAS.

Disabling System Restore in XP: Right-Click My Computer and select properties and click the system restore tab, Select “Turn off System Restore” and click OK.
Disabling System Restore in Windows 7: Right-Click My Computer and select properties, click the System Protection link, Click the Configure Button and select “Turn off system Protection”, OK, OK

In conclusion, one can use snapshots in lieu of system restore to gain some performance in the Windows guest but it’s a compromise since the taking and deleting of snapshots is a manual process.

“How to stop the ‘SBCore Service’ Service” or “How to use SBS2003 as a normal server”

AKA How to stop Windows SBS2003 from shutting down automatically.

Most of this info was found here: http://forums.speedguide.net/showthread.php?t=173731

Note: Removing this service apparently violates the license agreement for Microsoft Small Business Server. See the details here if you care.

Tools you’ll need – Process Explorer from www.sysInternals.com http://technet.microsoft.com/en-us/sysinternals/default.aspx

As you probably know, you have a service called “SBCore Service”, which executes the following process: C:WINDOWSsystem32sbscrexe.exe

If you kill it, it just restarts – and if you try and stop it you are told Access Denied.

If you fire up Process Explorer, you can select the process and Suspend it, now we can start to disable the thing.

Run regedt32.exe and find:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesSBCore

Right click this, choose Permissions and give the “Administrators” group on the local machine full access (don’t forget to replace permissions on child nodes).

Press F5 in regedt32 to refresh, and you’ll see all of the values and data under this key.

Select the “Start” DWORD and change it from 2 to 4 – this sets the service to the “Disabled” state as far as the MMC services snap-in (and windows for that matter) is concerned.

In the original instructions, the author left the service as Disabled and just denied access to the executable:

Next, adjust the permissions on the file C:WINDOWSsystem32sbscrexe.exe so that EVERYONE account is
denied any sort of access to this file.

Then go back to process explorer, and kill the sbscrexe.exe process, if it doesn’t restart – congratulations!

Load up the services MMC snap-in and you should find that “SBS Core Services” is stopped and marked as Disabled.

GrasshopperI decided that I wanted the service gone completely, so (after exporting it), I just deleted the registry key while in regedt32.

After rebooting, I verified that the service was indeed gone from the list of services in MMC, and there was no sbscrexe.exe process running. Then I moved the file sbscrexe.exe from C:windowssystem32 into a tidy little folder along with my exported registry key to keep for future evaluation. Something like a disgusting little bug under glass.

How to disable hibernation in Windows Vista

4GB of wasted hard drive space for something I don’t use.  Now you can disable it in 1 second:

  1. Win-R, cmd to open a command prompt.
  2. Type powercfg -h off and press <ENTER>.

That’s it.

“the iscsi name specified contains invalid characters or is too long”

This applies specifically to the iSCSI Intiator for Windows XP, but might apply to other versions as well. 

Check to see if there are underscores in your volume group and/or volume names.

Downgrading from Vista to XP on Gateway MX8711 and similar Vista-only laptops without a floppy drive.

OK, I was going to finish this off at some point, but I’ve gotten busy with other projects, so I figure I might as well post what I have so far…  If there’s any interest, let me know and I’ll see if I have any more useful insight… 

 Step 1: Get this stuff:

Step 2: Make a new XP CD:

  • Install nlite
  • Create a new XP CD, and slipstream the Intel drivers you downloaded in Step 1 using nlite.

Step 3: Install Windows XP:

  • Installation should be straightforward if you have created your new XP CD properly.  The hard drive will be detected without having to press F6, and the network card and video card will work out of the box.

Step 4: Find the other Gateway drivers (I managed to find a laptop in the 64xx series that had most of the same internals, and XP drivers…):

  • Audio: (SigmaTel Unknown @ Intel 82801GBM ICH7-M – High Definition Audio Controller [B-0])
  • Wireless: (Broadcom 802.11g Network Adapter) 
  • XP Update for Modem to work properly:
  • Modem: (Motorola SM56 Data Fax Modem)
  • Touchpad:
  • Card Reader:

SBS2003 Exchange POP3 Connector Polling Interval

A quick registry fix revealed here shows how to increase the POP3 email retrieval speed on Small Business Server 2003.  Yes, having SMTP mail delivered directly to the server is better, but first things first!

1. Locate and then click the following registry subkey:
“HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/SmallBusinessServer/Network/POP3 Connector”

2. On the “Edit” menu, point to “New”, and then click “DWORD Value”.

3. Type “ScheduleAccelerator” as the entry name, and then press ENTER.

5. On the “Edit” menu, click “Modify”.

6. In the “Value data” box, type the value that you want, and then click “OK”.  To determine the polling interval, the value that is configured on the “Scheduling” tab in the GUI is divided by the value that you type for the ScheduleAccelerator entry. For example, if a 15 minute interval is specified in the GUI and you set the value of the ScheduleAccelerator entry to 3, the connector will poll every five minutes.

7. Quit Registry Editor and restart the “Microsoft Connector for POP3 Mailboxes” service.

Note: I’m not entirely convinced that the “[GUI Interval]/[ScheduleAccelerator]=[Minutes]” theory is correct.  With the server set at 15/5, I should get polling every 3 minutes, but it seems to be more like 45 seconds.  With it set at 15/3, I am getting mixed results between 30 seconds and 5 minutes.  I guess that’s good enough for government work; YMMV.

Disconnect Remote Desktop Sessions

Thanks to Scott Forsyth, I found a way to disconnect remote desktop sessions when you are unable to connect to the server via RDP…  Apparently qwinsta and rwinsta are built-in to Windows (XP Pro at least).

Scott said:

qwinsta /server:12.12.12.12

Where 12.12.12.12 is the IP address or name of the non-accessible machine.

This will display something like this:

> qwinsta /server:12.12.12.12
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
 rdp-tcp#470       Bob                       1  Active  rdpwd
 rdp-tcp#471       Jane                      3  Active  rdpwd

Now I know that Bob and Jane are the two that are logged in.  Since Jane left the office 20 minutes ago I know that she forgot to log off.  I don’t know where Bob is but I only need one session so I’ll ignore him for now.

To disconnect Jane’s session I would type this:

rwinsta /server:12.12.12.12 3

Notice the 3 which is the session ID I found from using qwinsta above.

Codename: Chicago

Things I hate:
– Googling “hp 1020 vista drivers” and coming across 1,000,000 posts from people who want to let me know they hate Microsoft but have no useful information to share.
– Being told by HP that Microsoft’s new operating system does not support my laser printer (but don’t worry, we’re working on it), and by the way, your scanner is too old to ever be supported – please buy a new one.
– Deciding to use my printer and scanner on my XP machine after all, only to find out the driver downloads are 50MB each.

Things I love:
– Googling “linux hp 1020” and coming across foo2jzs; then being able to print in less than 5 minutes. 8 minutes including downloading foo2jzs; on dial-up (1.4 MB) thanks to SLMODEMD.gcc4.1.tar.gz, but that’s another story.
– CentOS 5 already knowing everything it needs to know about my ancient scanner (HP ScanJet 2200c) and just working.

OK, so Gnome/OpenOffice is not nearly as pretty as Vista/Office 2007 to use, and I have to start my modem using a shell script for now, but at least I can make simple photocopies using the equipment I already own… I can’t wait to plug in my digital camera to see what happens.