Saturday, April 21, 2007

Recover Shift-Deleted items

I've had several Outlook users come to me asking to recover messages they've just accidentally deleted. When asked, they confess to have used Shift-Delete (permanent delete). What to do?

Outlook has the feature of being able to Recover Deleted Items, but by default it is only active for the Deleted Items folder. All other folders show the selection under the Tools menu grayed-out.

Through the registry on a workstation, you can configure Outlook to allow Recover Deleted Items for any folder.

1. Exit Outlook (if open)
2. Launch the Registry Editor (regedit or regedt32)
3. Expand HKLM\Sofware\Microsoft\Exchange\Client\Options
4. In the right pane, if there is a DWORD entry named DumpsterAlwaysOn, skip to step 7
5. Go to Edit-->New-->DWORD Value
6. Without any spaces, type the name DumpsterAlwaysOn
7. Set the DWORD value to 1 (value of 0 disables the feature)
8. Exit the registry editor
9. Launch Outlook

Gathering password change dates

This came about when my IT staff was tasked with preparing the company for mandatory password changes forced by Group Policy. We wanted to give everyone a chance to change their password once before the GPO locked them out of their accounts. For several weeks I had to gather all the password information to see who we needed to talk to.

I also wanted a distributable report, so I read up on populating Excel spreadsheets from the Microsoft Script Center website (see my links section). I included some pretty-print features like autoformatting the column widths, making the column headings bold, and performing a sort on the data.

The script has duplicate sections to pull data out of different OUs. You can add or remove as many of this section as desired. Just change the LDAP section to point to the appropriate place in your AD forest.

Copy and paste the following into a file named PASSWORDDATES.VBS then edit.

'* This script creates an Excel spreadsheet showing users and
'* their last password change date. Running this script assumes
'* you have MS-Excel loaded on the workstation.
'* - Dean T. Uemura

'* Execute the script by typing:

'* CSCRIPT PASSWORDDATES.VBS at a command line prompt
'* PasswordFile holds the name of the spreadsheet and

'* will be saved in My Documents

Const PasswordFile = "passwords.xls"
set objFSO = CreateObject("Scripting.FileSystemObject")
set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add

'* Establish Header Row - make them 12-point bold print
objExcel.Cells(1,1).Value = "User"
objExcel.Cells(1,2).Value = "Location"
objExcel.Cells(1,3).Value = "Password Date"
set objRange = objExcel.Range("A1:C1")
objRange.Font.Size = 12
objRange.Font.Bold = TRUE

iWriteRow = 1

on error resume next

'* Each user OU is done separately in this script
wscript.echo "OU1"
set objOU = GetObject("
LDAP://ou=OU1,dc=mydomain,dc=com")
objOU.Filter = Array("user")
for each objUser in objOU
iwriteRow = iwriteRow + 1
'* wscript.echo objuser.name
dtmValue = objUser.PasswordLastChanged
objExcel.Cells(iWriteRow,1).Value = objUser.Name
objExcel.Cells(iWriteRow,2).Value = "OU1"
objExcel.Cells(iWriteRow,3).Value = dtmValue
next

wscript.echo "OU2"
set objOU = GetObject("
LDAP://ou=OU2,dc=mydomain,dc=com")
objOU.Filter = Array("user")
for each objUser in objOU
iwriteRow = iwriteRow + 1
'* wscript.echo objuser.name
dtmValue = objUser.PasswordLastChanged
objExcel.Cells(iWriteRow,1).Value = objUser.Name
objExcel.Cells(iWriteRow,2).Value = "OU2"
objExcel.Cells(iWriteRow,3).Value = dtmValue
next

'* Autofit the column widths
set objRange = objExcel.Range("A1")
objRange.activate
set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
set objRange = objExcel.Range("B1")
objRange.activate
set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
set objRange = objExcel.Range("C1")
objRange.activate
set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()

'* Sort by Location then Dateset
objRange = objExcel.Range("A1").SpecialCells(11)
set objRange2 = objExcel.Range("B1")
set objRange3 = objExcel.Range("C1")
objRange.Sort objRange2,,objRange3,,,,,1

'* Save the Spreadsheet file
set objWorkbook = objExcel.ActiveWorkbook
objWorkbook.SaveAs(PasswordFile)
objExcel.Quit


Command Prompt window tips

Tip#1 - Entering a path+file into a command line

I find myself occasionally pining for the old MS-DOS days of typing everything from a command prompt. Then I have to type in a command with a long path and file embedded and I snap back to the present time. Here's a tip I paid for - actually I got it during a call I'd put in to Microsoft's PSS (Exchange) and this was something I was directed to do by the PSS Engineer.

1. Open a command prompt window (CPW)
2. Open Windows Explorer and drill down to a subfolder (say in My Documents)
3. Position the two windows so that when Explorer has focus, you can see at least part of the CPW
4. Click on the desired file and drag it to the CPW

Look at the CPW. You'll see the entire path+file, and if there are any embedded spaces, the entire thing is surrounded by double-quote marks! The entry gets inserted at the cursor location, so you can even place it in the middle of a typed command.

Tip#2 - Command history

If you're like me, you occasionally run into a situation where you have to repeat commands, not always in the same order. There's always the up-arrow and down-arrow to scroll through the previous commands, but there's got to be a better way right? Especially if you need to repeat a command you typed ten lines ago, then have to redo the one you just did.

Did you know that from earlier days of MS-DOS, there was a history buffer? I didn't until I was in another PSS call. With the focus on a Command Prompt window, the F7 key displays your history, and all commands are accessible by scrolling up and down with the arrow keys. Pressing Enter on any of them repeats the command.