Simple powershell network backup script using wbadmin

I needed a simple script to backup a server running Windows Server 2008 to a network location with email reports.

At first I did some prerequisites(the steps marked with * at the beginning aren’t absolutely necessary):

*1. Create a CNAME on my dns for the server where the backups reside: backup.mydomain.com .

2. Create a share on the backup server.

3. Create the folder structure for the backups: on the root of the share create a folder named exactly as the server (the result of hostname command on the backed up server); create in this folder 7 other folders named by each day of the week -monday, tuesday,wednesday, thursday, friday, saturday, sunday.

 

The script:

#—————————————————–Start script—————————————————————-

function SendEmail($To, $From, $Subject, $Body, $attachment, $smtpServer)
{
        Send-MailMessage -To $To -Subject $Subject -From $From -Body $Body -Attachment $attachment -SmtpServer $smtpServer
}
$emailto=”your_email@yourdomain.com
$emailfrom=”backup@yourdomain.com
$day=(get-date).dayofweek
$hname=hostname
$backuplocation="\\backup.yourdomain.lan\backup$\$hname\$day\"
$backuplog="$backuplocation"+(get-date -f MM-dd-yyyy)+"-backup-$hname.log"
$emailserver="mail.yourdomain.com"
Write-Output ("———————– Backup started on – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append
$Error.Clear()
wbadmin start backup -backupTarget:$backuplocation -include:"d:,e:" -allcritical -vssfull -quiet | Out-File "$backuplog" -Append
if(!$?)
    {
        Write-Output ("———————– An error has occurred! Check it please!. – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append
        SendEmail -To "$emailto" -From "$emailfrom" -Subject "backup failed" -Body "The backup has failed! Please check attached log." -attachment "$backuplog" -smtpServer "$emailserver"
        break
       
    }

Write-Output ("———————– Everything is OK! – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append
SendEmail -To "$emailto" -From "$emailfrom" -Subject "backup $hname ok" -Body "The backup has succeeded!" -attachment "$backuplog" -smtpServer "$emailserver" .

#——————————————————–End script——————————————————————

Save it as a yourname.ps1 file and create the scheduled task accordingly to your needs. Below how you should start the task from the schedule tasks Actions.

scheduled

If your smtp server requires authentication create a separate account for this and update the SendEmail function so that it includes the

“–Credential” switch.

As you can see all the variables are defined at the start of the script:

$hname – is the name of the host that’s backed up

The rest of the variables are pretty straightforward.

What does the script:

1. Backup to a network location of your choice.

2. Create a backup log.

3. Check if the backup ended successfully/unsuccessfully.

4. Send an email with the result: success/failure and the log is attached.

Of course if you need to keep the backups more than a week you’ll have to copy them from there since wbadmin clears the folder where it creates the backup.

WSUS: Error 10032 Source Windows Server Update – Solved

 

I was consistently getting the error 10032 on the server that hosts my WSUS 3 server.

Wsusdebug0

The error sounded so generic that I first looked on http://eventid.net for the error. One of the sollutions pointed to this:

http://www.microsoft.com/technet/support/ee/transform.aspx?ProdName=.NET+Framework&ProdVer=2.0.50727&EvtID=10032&EvtSrc=Windows+Server+Update+Services&LCID=1033

  1. Open a command window.
  2. Type sc config bits start= auto
  3. Type net stop bits && net start bits
  4. Type net stop wsusservice && net start wsusservice
  5. Start WSUS 3.0: Click Start, click Administrative Tools, then click Microsoft Windows Server Update Services v3.0.
  6. Click Synchronization Results.
  7. In the Action pane, click Synchronize Now.

and in the end:

  1. Type cd <WSUSInstallDir>\Tools
  2. Type wsusutil checkhealth
  3. Type eventvwr
  4. Review the Application log for the most recent events from source Windows Server Update Services and event id 10030.

Now when checking the eventviewer I get error 10032 and a more consistent error 364 source Windows Server Update:

Wsusdebug1

After a new search this: http://msmvps.com/blogs/athif/archive/2005/10/27/Purge-Delete-the-downloaded-patches-on-WSUS-Server.aspx

pointed me to the solution: WSUSDEBUG PurgeUnneededFiles .

You simply donwload the WSUSDEBUG tool(server diagnostic tool) from here: Server Diagnostic Tool

Unpack it to any location on the server that you like (ex: C:\Program Files\Update Services\Tools ), and run:

WsusDebugTool.exe /Tool:PurgeUnneededFiles

Wsusdebug2

That solved my problem and also cleaned up to 10GB on the drive that the WSUS content resided.

Of course that depends on the Products and Classifications options that you’ve chosen for your server.

After WSUSUTIL checkhealth I got in eventviewer these 2 events(10030 and 10000):

Wsusdebug4Wsusdebug3

That means that everything is ok with the WSUS server Smile

More WSUS Server stuff here:

http://technet.microsoft.com/en-us/wsus/default

Outlook 2007 Missing Autoarchive button

This sounds and it was really stupid (or seemed like).

What would you say if one day you’ll be asked to change some archiving options in MS Outlook 2007?

Obviously in the main MS Outlook window you’ll go : Tools – Options – Other ….

And presume that the window would look like this (below) ?

Where’s the Autoarchive button? Yes, I intentionally took it out this time with Paint.NET . Same as with the folders and sections that wouldn’t be of interest to all the internet.

But that nice pic was for real when I tried to change some autoarchive settings for one of my coleagues.

So if you’re not interested on the whole story but only on the solution simply skip to the underlined section.

I should mention that in the firm that I work only a few of the users have administrative rights on the computers, the user in this case didn’t had administrative rights and no other used her computer.

The antivirus (Kaspersky) was up to date and on the administration server I didn’t found any history with viruses. This user/computer didn’t had a retention policy for Outlook.

Of course I checked all this before going to the internet in search of a solution.

Of course the first post I did find told us about a retention policy, then I triplechecked, gpupdate /force, restart computer check with gpmc – group policy results, manually going over the container etc

Of course that was stupid because I previously checked with some users/computers that belong to the same OU’s (belong to the same department) and they didn’t had the problem.

Again search the internet, and stumble upon this post of some guy Kermit that posted on EggHeadCafe:

http://www.eggheadcafe.com/community/aspnet/97/10236332/archive-and-autoarchive-features-missing–they-were-there-a-few-month.aspx

It was saying something about a MS patch like KB2412171 . Never payed much attention to the KB numbers even when approving them on WSUS; I prefer to read the info and . I dismissed the idea without even searching for this patch. Usually, MS patches are composed of 6 numbers and usually the number begin with a 9 . So in my mind I sad that this guy was either wrong or trying to have some fun. Other posts had ideas with viruses and other silly things.

I made a repair/install of office and still nothing.

Finally I said: let’s look for this silly KB2412171 . Of course it exists and it’s here: http://support.microsoft.com/kb/2412171

Looked for the patch on the client computer and voila! there it was. Unistalled it, restarted the computer and what do you think:

the Autoarchive button was back!

Further investigating I found that I didn’t approve the patch on the WSUS server for any computer.

The full explanation of this situation (no other computer in my firm had this patch or problem) was that the computer was updated previously of beeing joined to the domain, so it became WSUS server client only after had been updated and got this magnificent patch.

It took me a hard 2-3 hours to figure this out.

So guys beware of the evil KB2412171 patch!

Joking of course 🙂

this is provided only as info.

Offline registry editing + regional settings

Always the most annoying problems are linked to when we migrate users to a new profile and those little but essential settings that are in place.

So after such an operation I was in the situation that an MS Access app wasn’t displaying what it should for the user and that was designed by a coworker that was in holidays (of course) and he made all of the regional settings by himself. He did port the app from Access 2003 to Access 2007 which we use. Of course, he rather modified the default regional settings that we use than make the modifications in his app.

So how could we reproduce the regional settings from the old profile to the new one?

Since I kept the old user profile I needed to connect to the offline user profile offline.

We’ll need the old user profile and the new one.

The user (target user profile) should be logged off (better make a restart of the computer before proceeding).

We’ll open each user profile in separate regedit windows for easier comparison:

1. Go to Start – Run and type regedit or Start – Type in Search Programs or Files regedit – Click on it.

2. Click on HKLM (HKEY_LOCAL_MACHINE).

3. From the File Menu select Load Hive and browse to the old user profile.

The registry hives are located as follows:

All except of HKEY_CURRENT_USER: %SystemRoot%\System32\Config .

HKEY_CURRENT_USER (or the user which has the settings of interest ) c:\Documents and Settings\username under Windows XP

c:\users\username under Windows Vista, 7

4. Type a key name in the Load Hive window.

5. Open another regedit as in step 1 and follow steps 2-4 for the new user profile.

6. The regional settings are located in HKEY_CURRENT_User\Control Panel\International .

7. Now all you have the two different hives opened and all you have to do is to reproduce the settings from the old one to the new one.

For more detailed info about the keys referring to the regional settings in registry try here:

http://technet.microsoft.com/en-us/library/cc978632.aspx

More details about registry hives:

http://msdn.microsoft.com/en-us/library/ms724877

and of registry:

http://support.microsoft.com/kb/256986

Rate my network diagram

http://www.ratemynetworkdiagram.com is a site were you can see what others have done with their network, upload your own network and rate the networks.

Seems to me like a very nice thing.

Here’s a sample from the site:

large_network

It’s the mmkholy site member’s diagram.

Of course there are sections like: big networks, home network etc so everyone has a place here.

Just enjoy it.

Office 2010 Home & Business Offline installer

I needed such an offline installer for the Office 2010 package and all I was getting was the Office click to Run installer (grrrrrr). Probably they were thinking that’s what everybody needs. So the first option you get is this Office click to Run that will install the office pack on your computer almost completely unattended.

Finally I got to the offline installer link (it took a while, so you’re sparred of the annoyance following the link below), so here it is:

https://www7.buyoffice.microsoft.com/usa/downloader.aspx?local=true&cache=181419843&receipt_id=561049834&culture=en-us

Gamers Bill of Rights

Well this is it 🙂

Check them out here: http://www.gamersbillofrights.com/

gamersrights

Some things are never going to happen.

These I like the most:

7. Gamers have the right to re-download the latest version of the games they purchase.

That means if I bought SC2 now I shouldn’t have to buy it again if I want to play the protoss or zerg campaigns that will appear in the future.

8. Gamers have the right to use their games without being inconvenienced due to copy protection or digital rights management.

Meaning no need for f*****g DVD your DVD Unit or other nice checks that burry your game performance in the most interesting moments…

9. Gamers shall have the right to play single player games without requiring an Internet connection.

All this annoying protections sometimes help us use a pirated copy of the game; you figure out why.

Off course there will always be some people who will use ONLY pirated copies. But so is in life: some never buy tickets for travelling with the bus, some never learn in school, some never work when at work and so on…

Obtain MSI files from JAVA installer package – Group policy deployment

I needed this for deployment through GPO so I find this article:

http://www.java.com/en/download/help/5000011100.xml

Basically it says that you need to run the installer so that it’s unpacking the files. Don’t go further with the instalation.

You’ll need to copy the files from this location:

Vista/7: C:\Users\%username%\AppData\LocalLow\Sun\Java\

XP: C:\Documents and Settings\%username%\Local Settings\Application Data\

2000: C:\Documents and Settings\<User>\Application Data\

Here you’ll find a (some) folders named by the java version number.

Simply copy the folder with the version you’re interested to a share on the network and add it to the Group Policy:

[Computer Configuration/User Configuration] – Software Settings – Software Installation – New Package.

Use it as Assigned or Published.

Outlook 2007 doesn’t show the File, view… menu

When this happens and it doesn’t start in outlook /safe with the following message:

Cannot start Microsoft Office Outlook. Cannot Open the Outlook Window

you could try outlook /resetnavpane . It solved the problem for me.

Also the complete list of outlook switches:

http://office.microsoft.com/en-us/outlook-help/command-line-switches-for-microsoft-office-outlook-2007-HP001218589.aspx

Thanks to:

http://www.techforlunch.com/cannot-start-microsoft-office-outlook-cannot-open-the-outlook-window/