Bits of Tech

Icon

Tips & Tricks from IT Pros

Quick Tip: Enable Exchange ActiveSync on a Mailbox with PowerShell

Exchange 2007 brought some changes to managing mailboxes, most notably, the removal of Exchange tabs from Active Directory. In Exchange 2003, to enable Exchange ActiveSync for a mailbox, you would simply open the ADUC properties for a user, click the Exchange Features tab, click Exchange ActiveSync, and then click Enable.

Today, with Exchange 2007 and Exchange 2010, the function isn’t quite as easily found, but it’s much easier to use. On any machine with the Exchange Management Tools loaded, fire up the Exchange Management Shell (this won’t work in your regular PowerShell terminal) and type the following, replacing “Firstname Lastname” with the user’s first and last name, or their user ID, in quotes.

Get-Mailbox "Firstname Lastname" | Set-CASMailbox -ActiveSyncEnabled $true

 

Related Posts

Delete Temporary Internet Files from All Profiles in Windows 7 or Vista Using PowerShell

This is just a minor update to the previous script, modified for Windows 7 and Vista machines.

#==================================================================================
# Delete_Temp_Files_W7.ps1
#
# Author: Bill Clark (http://bitsoftech.net/)
#
# This script deletes all files in all users' Temp and Temporary Internet Files
# folders on a Windows Vista or Windows 7 machine.
#
#==================================================================================

<#

.SYNOPSIS

Deletes all files and subdirectories in %UserProfile%\AppData\Local\Temp and
%UserProfile%\AppData\Local\Microsoft\Windows\Temporary Internet Files for all user
profiles on the machine.

.PARAMETER

No parameters are accepted by this script.

.EXAMPLE

Delete_Temp_Files_W7.ps1

.NOTES

The script will not remove any files that are in use by other processes, and will
throw an error upon encountering any in use files.

#>

# Create array containing all user profile folders
$colProfiles = Get-ChildItem "C:\Users\" -Name
# Remove the All Users profile from the array
$colProfiles = $colProfiles -ne "Public"

# Removes temporary files from each user profile folder
ForEach ( $objProfile in $colProfiles ) {
    # Remove all files and folders in user's Temp folder
    Get-ChildItem "C:\Users\$objProfile\AppData\Local\Temp\*" -recurse | remove-item -force -recurse
    # Remove all files and folders in user's Temporary Internet Files. The -force switch on Get-ChildItem gets hidden directories as well.
    Get-ChildItem "C:\Users\$objProfile\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -recurse -force | remove-item -force -recurse
}

Related Posts

Delete Temporary Internet Files from All Profiles in Windows XP Using PowerShell

As a systems administrator, I re-image systems quite often. Part of my re-imaging process entails copying the “Documents and Settings” folder containing the user profiles to a disk on my server, dropping a fresh image on the drive, and then copying the user profiles into C:\Recovered_Profiles before shipping it back to the location that sent it in. This allows the local IT team member to move the data into the users’ new profiles after their first logon.

The transfer of user profiles can take a very long time depending on the amount of data in each profile, but also upon how many files are in the Temp and Temporary Internet Files folders inside each profile. It’s not the size of the files in those folders that will cause extended transfer times, but the sheer number of small files in the folders. There can be thousands upon thousands of files in the Temporary Internet Files folder, and each file accounts for a separate read transaction on the hard drive. For this reason, I wrote a VBScript a year or so ago to clear out these two folders, but it never really worked 100% of the time. I’d still end up with 2-3 profiles (out of 20 or so) that had temp files, but it was better than nothing.

Enter Windows PowerShell. I was able to condense the 60 or so lines of VBScript required to empty those two folders into the script below, which is fewer than 10 lines of actual code. In fact, there are nearly twice the number of lines of comments in the script than lines of code when you count the “help” section at the top of the script. I’ve tested this script on 10 different machines, and it hasn’t left any temp files behind other than files that were in use at the time I ran the script (most commonly the index.dat file in the IE cache folder).

UPDATE: I have posted a modified version of this script for use on Windows 7 and Vista machines in the post titled Delete Temporary Internet Files from All Profiles in Windows 7 and Vista Using PowerShell.

#==================================================================================
#
# Delete_Temp_Files_XP.ps1
#
# Author: Bill Clark (http://bitsoftech.net/)
#
# This script deletes all files in all users' Temp and Temporary Internet Files
# folders on a Windows XP machine.
#
#==================================================================================

<#

.SYNOPSIS

Deletes all files and subdirectories in %UserProfile%\Local Settings\Temp and
%UserProfile%\Local Settings\Temporary Internet Files for all user profiles on the machine.

.PARAMETER

No parameters are accepted by this script.

.EXAMPLE

Delete_Temp_Files_XP.ps1

.NOTES

The script should be run while logged in as Administrator, or run with Administrator privileges.

The script will not remove any files that are in use by other processes, and will throw an error upon encountering any in use files.

#>

# Create array containing all user profile folders
$colProfiles = Get-ChildItem "C:\Documents and Settings\" -Name
# Remove the "All Users" profile from the array
$colProfiles = $colProfiles -ne "All Users"

# Removes temporary files from each user profile folder
ForEach ( $objProfile in $colProfiles ) {
	# Remove all files and folders in user's Temp folder
	Get-ChildItem "C:\Documents and Settings\$objProfile\Local Settings\Temp\*" -recurse | remove-item -force -recurse
	# Remove all files and folders in user's Temporary Internet Files. The -force switch on Get-ChildItem gets hidden directories as well.
	Get-ChildItem "C:\Documents and Settings\$objProfile\Local Settings\Temporary Internet Files\*" -recurse -force | remove-item -force -recurse
}

Related Posts

Learning the Wonders of Windows PowerShell

I’ve been using VBScript for systems management and task automation for many years. From working with Active Directory to manipulating files and folders, VBScript has been an excellent tool for me. I’ve read little bits and pieces about Windows PowerShell for a while now, and I always thought it would be too confusing to jump into without really having the time to devote to learning it well. I started using PowerShell 6 months ago for some basic Active Directory tasks because of the better integration, and it’s greatly simplified making mass changes to Active Directory.

In the past few days, a colleague of mine inspired me to dig into PowerShell a little more. I picked up a copy of Windows PowerShell Cookbook last night, and started reading this morning at work. This book has definitely made things easier to understand, so I definitely recommend it to anyone that is interested in learning PowerShell. Today, I ported a few VBScripts I use somewhat regularly to PowerShell, and was amazed at the reduction in lines of code needed to complete some of the tasks. For example, I wrote my most frequently used VBScript to delete all files in the Temp and Temporary Internet Files in all Windows XP user profiles on a machine. It was about 60 lines of code. I duplicated the functionality of that script in fewer than 10 lines of code. It surprised me to find I had more lines of comments than actual code!

Over the next few weeks, I’m going to finish up this book. In the process, I hope to create quite a few more scripts to help automate some of my management tasks, and I’ll share those scripts here.

Related Posts

I Made an Appearance on FastCompany with Gina Trapani!

Recently, I had the opportunity to speak with Gina Trapani of Lifehacker and ThinkUp! fame. I submitted a question that had been bothering me for some time to Gina for the Work Smart 2 series for FastCompany.

My question, which you can hear in its entirety in the video below, was about where to draw the line and start getting things done when you’re constantly looking for the next best way to be more productive.

My question was selected, and I had a great time filming our Skype chat and getting my question answered. I don’t want to spoil the video for you, but I’m excited to say that Gina called in the big guns for assistance and got some feedback from David Allen (Getting Things Done, Making it All Work).

It was a great pleasure to speak with Gina, and to get a fresh perspective on productivity. Thanks again, Gina, for your time!

Related Posts

  • No Related Posts

Automating WordPress Backups using Automator and Transmit

After publishing Bits of Tech with WordPress for a couple of months, I was looking for an easier way to backup my WordPress installation. From the beginning, I was running a backup every weekend using Transmit to download the whole directory housing my WordPress install, then compressing the downloaded directory, renaming it with the date and moving it to my backups folder.

Knowing that there had to be a better way, I looked at using AppleScript and Automator, eventually settling on Automator. While my process may differ slightly from yours due to differences in hosting providers, it should be very similar to how I do it. Today, I’m going to share my process step-by-step in hopes that someone else can benefit from it, and even improve upon my process.

As I mentioned earlier, I use Transmit 3 by Panic Software. The first thing I did was create a Favorite for my SFTP site. My hosting provider, DreamHost, gives you a home directory, and in that directory you can create a new directory for every domain you host, so the default path in my favorite is set to my home directory. Here’s a picture of my favorite, with my username obscured.

transmit-fav.png

First, we need to create some folders for the backups. In my user profile folder, under the Sites folder, I have created a folder called Backups. Inside Backups, I’ve also created a folder called Temp. That’s where our download will be stored temporarily before we compress it. Inside this folder, create a folder with the same name as the directory on your FTP server that houses your WordPress install. In my case, it’s bitsoftech.net. This is just a temporary folder that we’ll use later to create an action (without having to download the whole directory first).

Now that I have the favorite defined and the folders created, we can move along to creating our Automator script. Open up Automator from the Applications folder, and when you’re presented with the “Choose a starting point to open a new workflow” window, choose Custom and click Choose. You should now have a new, blank workflow.

The first step is to set up an action to download our directory containing our WordPress installation. In the left sidebar, choose the Internet category under Library. If you have Transmit installed, you should see the Transmit icon with Download Files next to it in the pane just to the right of the Library. Drag that into the large right pane of the Automator window, and you have your first action in the workflow.

Now we need to configure the Download Files action. Where it says Connect To choose Favorite. Next, choose the name of the favorite you created for Favorite. In my case, it’s DreamHost Root. For Resume Mode, choose Replace. Now we choose our destination for the downloaded files. Click Destination, then choose Other…, and you’ll be allowed to browse to your folder. Choose the Temp folder under your Backups folder. Lastly, we have to choose our Remote File Path. Click the + symbol below the Remote File Path box, and type the path to your files. Since my favorite points to my home directory, I will enter the directory that holds the WordPress installation, bitsoftech.net/. Make sure you put the trailing slash in path or Transmit will only download the folder and not it’s contents. See the example below.

dl-files-automator.png

Our next step is to create an archive of our downloaded files. Under the Library in the left pane of the Automator window, click Files and Folders, then locate Create Archive and drag that into the right pane of the window just below our Download Files action. You’ll notice that there’s now a triangle protruding from the bottom of the Download Files action connecting it to Create Archive. This means that the output of Download Files—the directory we downloaded—are the input that Create Archive will use.

In the box labeled Save As, we will give the archive a name. I am using Bitsoftech-(date)-(time).zip. The (date) and (time) are variables that Automator will populate itself. To create the name, type the name you want to use, such as Bitsoftech-, then click the Variables button above Library in the left pane of the Automator window. Choose Date & Time, and drag Today’s date to the Save As box in the Create Archive action on the right. Click the little white triangle inside the Today’s Date bubble you dragged over and choose Edit. From the Format drop down menu that appears, choose Custom Format. Now drag the Month, Day of Month, and Year bubbles into the box above them. Next, click the little triangle inside the Month and Day of Month bubbles and change the format to “01″ and “05″, as shown below, then click Done.

date-variable.png

Now, back in the Save As box in the Create Archive action, type another hyphen, then go back over to the Variables under Library and drag Current time over into the Save As box. Click the little triangle in the Current Time bubble, choose Edit, then Custom Format from the drop down menu. Drag the Hour and Minute to the box above them. Inside the hour bubble, click the triangle and choose “01-24″ so our hours are displayed in military time. Leave the Minute bubble as it is, then click Done. After the Current Time bubble in Save as, type .zip. From the drop down menu next to Where, choose Other… and navigate to your Backups folder or wherever you want to store the archive. Check off Ignore Unreadable Items, and your action should look similar to the image below.

create-archive-action.png

Now that our download and archive actions are complete, it’s time to do some cleanup. Choose Actions from just above Library in the left pane again, select Files and Folders, and drag Get Specified Finder Items over to the right pane of the window just below Create Archive. Now, from the Action menu at the top of the screen, choose Ignore Input. You’ll notice that the triangle connecting Create Archive and Get Specified Finder Items disappears and the two are no longer linked. This is very important, otherwise Get Specified Finder Items will take the items you specify and the archive you just created and move them to the trash in our next step.

Click the Add button at the bottom of the Get Specified Finder Items action, then navigate to your Temp folder, select the directory inside it and hit Add. Your action should now look like the image below.

get-items.png

Now, we’re going to move that folder to the trash. Back in the left pane under Library, then Files and Folders, drag Move Finder Items to Trash just below your Get Selected Finder Items action. You’ll notice that Get Selected Finder Items and Move Finder Items to Trash are linked. This means that the items you selected in the Get Selected Finder Items will be moved to the trash. This cleans out your Temp folder for the next time you run the workflow.

The last action in the workflow is to quit Transmission. Under Library in the left pane, click Utilities, then drag Quit Application to the right pane below Move Finder Items to Trash. From the drop down menu, choose Transmit. If it doesn’t show up, choose Other… then navigate to your Transmit application. Uncheck Ask to save changes, and your workflow is complete.

Now, we have to save our workflow. From the File menu at the top of the screen, choose Save As…, then change the File Format to Application. Give it a name at the top of the window—I used “Bits of Tech Backup”—navigate to where you want to save it, then click Save.

Now you have a simple one-step process to back up your WordPress installation. You can manually run this backup by double clicking the icon, or you can schedule a cron job to run it automatically.

Related Posts

Create Custom Office 2007 Installations

UPDATE: The instructions provided here will also work for Office 2010 installations.

Today Bits of Tech brings you a video tutorial on creating custom Office 2007 installations using the Microsoft Office Customization Tool. This video takes you through the process of creating custom installs step-by-step. It also features a small segment on integrating the Office 2007 Service Pack 2 update into your installation media.

A good friend of mine loaned me his lab machine with Camtasia Studio 6 on it to create this video. Camtasia Studio is a great screencasting package, but it is a bit expensive at $299. After using his computer with the software on it, I will definitely be purchasing a copy for future video tutorials when my finances allow.

I had planned on sharing this video on YouTube, but the 10 minute video length restriction has prevented me from doing so. I will try to edit 3 minutes out of the video to fit it on YouTube, but no promises, because I don’t want to remove too much content.

ZD YouTube FLV Player

Related Posts

Arranging Menu Bar icons in Leopard

Got a few icons in your Menu Bar and you’d like to change the order they’re displayed in? You’re in luck, they’re fairly easy to move around. Just hold your Command key and drag them into the order you prefer.

Want to get rid of an icon? Hold the Command key and drag it off the menu bar. Gone!

This method doesn’t work with the Apple icons, but not with all apps. Some exceptions to this method are Google Notifier, Tweeie, and Adium. To rearrange these, exit the apps and relaunch them in the order you’d like them to appear from right to left. If they are apps in your Startup Items, you can change the order they launch in to reorder them in the menu bar.

Related Posts

Disable Leopard’s 3D Glass Dock

I’ve never been a big fan of the Leopard 3D glass dock effect, preferring the 2D dock effect that you see if you place the dock on the sides of your screen. While I personally keep my dock on the left side of the screen, you can get the same 2D effect at the bottom of your screen using a fairly simple terminal command.

Just open your Terminal app (located in Applications:Utilities), then paste in the following command and hit enter:

defaults write com.apple.dock no-glass -boolean YES; killall Dock

Your dock will exit and reopen in 2D mode, as shown in the image below.

dock2d

To disable the 2D effect, simply paste the same command into Terminal, replacing “YES” with “NO”.

Related Posts

Vendor for Discontinued Dell Power Supply Units

Recently, Dell has stopped providing replacement power supply units for their OptiPlex GX270 and GX280 Small Form Factor computers. Luckily, there is a vendor that supplies new parts (not refurb) for these machines. Circle Computer in Walpole, MA, has them in stock. While these computers are a bit on the old side, they function just fine for email, MS Office, and web surfing in many of my offices, so we were reluctant to dump the machines just for a faulty power supply. Contact info for Circle Computer is below.

Circle Computer
466 High Plain Street
Walpole, MA 02081

Phone: 508-668-8778
FAX: 508-668-9779
Web: http://www.circlecomputer.com/

Related Posts

  • No Related Posts

Archives

Follow Me on Twitter: @bill_clark