iPhone dead...and back

Today, all of a sudden, the screen of my AT&T iPhone 4S went black and it stopped responding. Hitting home button or pressing and holding 'power' button did not help. I connected it to a power source hoping somehow it just needed some juice yet there was no sign of charging animation on the screen, it was dead.

Then, my colleague suggested the following:
Try putting it in DFU mode to at least see if you can restore it. See instructions below.

  1. Plug your device into your computer.
  2. Turn off the device.
  3. Hold the Power button for 3 seconds
  4. Hold the Home button without releasing the Power button for 10 seconds
  5. Release the Power Button but keep holding the Home button
  6. Keep holding the Home button until you are alerted by iTunes saying that it has detected a device in Recovery Mode

I did and it worked. So, I had my iPhone back but it was as if I just bought it, I had to get my data back as well...

I connected it to iTunes on my Windows 7 x64 and attempted to restore the last backup. I got prompted for the backup password. After entering the password, a process seemed to start but never finished. Instead I kept on getting the following message:
"itunes could not restore the iphone because the iphone was disconnected"

I thought it might have been a bad password, that was not it. Upon entering a different password, iTunes warned me that I had incorrect password.

Then, I wondered if my iTunes was corrupted, that was not it. I downloaded the latest version ( and chose to fix my version to no avail.

At this point, I was worried that my backup was bad. Instead, it turned out that the fix was to connect the phone to a different usb port. As soon as I switched the usb port, restore started to progress and I got   my settings back.

Restoring did not bring my applications back, but that's easy to fix by choosing the apps to install after launching 'App Store' > 'Updates' > 'Not on This iPhone'


Can I use PowerShell functions before defining them

Yes and NO!

As I was learning syntax and intricacies of PowerShell, one of the first things I was told was that if I wanted to use a function, I had to define it first, which meant that I had to structure my script so that functions would be on top and the main script at the bottom. Obvious reason is that PowerShell parses the script sequentially starting from top, working its way to the bottom. This fact remains the same.

If you were always using PowerShell ISE and were not calling your script from the command line, this behavior would come as a surprise to you, because PowerShell ISE does not care where in the script the function is located. There is a dated but still a good intro to functions at this link that mentions this but does not clarify the point. You can see that in the comments.

So, should you define your functions before using them? Sure! Do not bet against command line.


Secrets of PowerShell Remoting

'Secrets of PowerShell Remoting' is the title of an eBook that can be downloaded from It's written by PowerShell MVP Don Jones and Dr. Tobias Weltner and is the most detailed of any documentation I have ever seen about the subject.

In a standard domain environment where http is used as the default remoting protocol, it may come down to a simple command that should be run in administrator PowerShell console session: `enable-psremoting`, yet it's dizzying to look at the number of scenarios and steps in the eBook, especially if you want to use https.

Don Jones mentioned that newer versions of the book will be hosted on


Copying recent files with PowerShell

I saw an interesting question in 'Scripting Guys' Facebook group today:

"I want to check which photos have changed or were added after a specific date on my disk, and copy those to the same path on my backup disk.

I managed to filter:

Get-ChildItem -Recurse | ? {$_.LastWriteTime -gt (get-date).adddays(-180)}
but I don't know how to pick each item's folder path and copy.

PS E:\fotos> Get-ChildItem Hornet01.jpg | fl *
And this file should be copied to L:\fotos\Hornet01.jpg"

Before I go about how I would solve this problem, I will explain a bit about how I store my pics and how I would copy them to a different drive.

I keep my pics in a network drive that's mapped as Z:, structure goes like this
Z:\Family\Pictures\{Year}\{Year.Month}\{Event or Place}\*.jpg

Note that Z:\Family\Pictures does not change, so we can think it of as the 'root'. Now, say, I wanted to find all the pictures in the last 6 months and copy them to a different drive maintaining the same structure like

Y:\MyPics\{Year}\{Year.Month}\{Event or Place}\*.jpg

For this, I need to do followings:

  1. Find all pictures that have changed in the last 6 months. 
  2. Get the 'unique' parent directory names of those pictures
  3. Replace those directory names with the new ones
  4. Create the destination directories
  5. Copy the files to new destinations

Well, I will talk about how this can be shortened to two steps but stick with me for the time being...

#1 has already been solved:

$recent_files=Get-ChildItem -Recurse | ? {$_.LastWriteTime -gt (get-date).adddays(-180)}

Of course, we could have filtered these if really wanted just pictures using "-filter" option but let's not bother with that for the moment.

#2 Now, we need to get unique directory names:

$unique_sourcedirs = $recent_files | %{ ($ } |unique

Note that we ended up with a "System.String" type that we are going to manipulate

#3 We need to replace the first part (ie.z:\family\pictures with y:\mypics):

$dest_dirs=$unique_sourcedirs | %{$_ -replace 'Z:\\family\\Pictures','Y:\MyPics'}

Interestingly, you have to escape backslashes with Powershell's escape character, which happens to be backslash as the first part of replace operator needs a 'regular expression' but not the destination.

#4 Create the destination directories. 
If destination directories do not exist, copy operation will fail. And I am not aware of any parameters that would tell copy to create the directories in the way. This is why we are creating them first.

$dest_dirs | % { if (! (test-path $_)) { new-item -itemtype directory -path $_ }}

#5 We are almost ready to copy.
We have the source file list, and we know that destination directories are created now but we need destination paths. We could use the techniques above to get the destination paths.

$recent_files | %{ 
$target = ($ -replace 'Z:\\family\\Pictures','Y:\MyPics'; 
copy-item ($_.fullname) $target}

I know, repeating code is just ugly, could not we combine the steps? Sure, above steps helps clarify the action items but it could be shortened to this:

  1. Find all pictures that have changed in the last 6 months
  2. For each file, determine the target directory name by replacing the parent directory name with the new name; create the destination directory if it does not exist; copy the file to new destination.

$recent_files | % { 
   $target = ($ -replace 'Z:\\family\\pictures','Y:\MyPics';
   if (!(test-path $target)){ new-item -itemtype directory -path $target }; 
   copy-item -path ($_.fullname) -destination $target -force -whatif

Couple of Notes:

  • All of the above code-snippet is actually a single line if you are typing it in command line, I introduced line-breaks for better readability.
  • Parameter -whatif is only to see what will happen. You should remove it when executing the command
  • Parameter -force is not necessary if there are no files in destination directory.


OS X 10.8 App Installation and Gatekeeper

OS X 10.8 Mountain Lion is here with us and so is a new security feature called Gatekeeper, which allows a user to only install applications that came from Mac App Store or from sources that have a certificate from Apple.

Gatekeeper options can be displayed by heading over to Settings > Security and Privacy

App Store is great but not so much for Enterprise as it is not realistic to expect in-house developed code to go through Apple every time. So, Developers who signed up with Apple get a Developer ID Certificate that can be used to sign the installation packages. Details of this process are explained here on the Official Apple pages and also here on 'unreleased notes' in layman terms.

If an application is not signed and is not available in the App Store, then Gatekeeper 'may' get in the way in its default form (Mac App Store + identified developers) but there are 'gotchas'.

Should I disable Gatekeeper?
You may be tempted to select 'Anywhere' option in Gatekeeper to avoid the hassle but consider this
Gatekeeper will "only" block the installation of applications downloaded from web.

You will still be allowed the installation of unsigned, non-flat packages:

  • if you already have a package repository on a network or USB etc. and copying from there
  • if you use tools like curl that does not set 'quarantine' flag (see below)
  • if you control click and choose open in Finder.
  • If you launch Installer App (`sudo /System/Library/CoreServices/`) and browse to the downloaded application
  • If you use command line as in `sudo installer -pkg /path/to/package -target /`
So, there are plenty of ways to let Gatekeeper work for you without disabling it.

Quarantine attribute on Downloaded Applications:
When you download any install package from Web with, let's say, Safari, a hidden '' attribute will be added to it.  You can use `ls -l@` to display those attributes. When you try to install such files, Gatekeeper will block the application!

You can use the following command to remove the quarantine attribute:
'xattr -d -r /path/to/downloaded/package'

This will stop the prompts that tells you what you may already know: "ApplicationName" is from an unidentified developer. Are you sure you want to open it?


Must watch this!

I had a blog post about time-less articles that I came across on Internet. TED is full of incredibly powerful speeches. Today, I watched some of them and decided to post the links here. This post will serve as a place holder for future video links.

Jill Bolte Taylor talks about 'brain'. It's very moving and enlightning

Alain de Botton talks about 'success'. What we mean by it now and realities of western-life

Alain de Bottom discusses shortcomings of secular life and what it can borrow from religion


Using Mac as the primary machine and fixing Synergy

I had this zen moment the other day, and realized that there is very little reason that's keeping me from using a Mac as my primary machine right now. Although I had my mac up on the second monitor, I realized that I was using it less, as it was not connected to my primary screen.

So, I swapped my Mac and PC. Now, my mac is connected solely to the primary screen in front of me (Samsung SyncMaster 245BW at 1980x1200) with a displayPort to DVI adapter. Unfortunately, that meant that my PC had to be connected using a VGA as that was the only other input. 

My PC is also connected to the 20" ViewSonic VP2030b (1600x1200) on my right via DVI.  I have dual ATI Radeon HD 5700 in CrossFire setup (4xDVI out), so I would like to get a monitor that supports dual DVI input but there does not seem to be many options out there that I like. In fact, I like Dell UltraSharp U2412 the most at this point but still trying to decide.

Anyway,  I did not want to use multiple keyboards and mouses anymore, so I wanted to try the latest version of Synergy (v1.4.9 as of this writing). I used Synergy at work on 10.7 for some time but quickly had to give up on it when I upgraded one of my Macs to 10.8. 

I set it up so that My Windows 7 x64 would be the 'server' and Mac OS X 10.8 Mountain Lion as the 'client'. Setting it up is not really difficult, there is a single synergy.conf file that has to be common to both client and server (see mine below). 

The biggest trouble was that back and forward buttons of my mouse stopped working on Mac side. That was really annoying when browsing web sites and after some google'ing I found out that this was an issue that has been experienced by several others.

Some posts in that google code link put me into the right direction and after some trial and error, I figured out that using 'Windows + [' key was like hitting back button key, and 'Windows + ]' key was acting as forward key.

I solved the problem by mapping mousebutton(4) to keystroke(Meta+BracketL) and mouse(button5) to keystroke(Meta+BracketR). The whole config file is shown below:

section: screens
                halfDuplexCapsLock = false
                halfDuplexNumLock = false
                halfDuplexScrollLock = false
                xtestIsXineramaUnaware = false
                switchCorners = none
                switchCornerSize = 0
                halfDuplexCapsLock = false
                halfDuplexNumLock = false
                halfDuplexScrollLock = false
                xtestIsXineramaUnaware = false
                switchCorners = none
                switchCornerSize = 0

section: aliases

section: links
                right = AHMac
                left = AHPC

section: options
        relativeMouseMoves = false
        screenSaverSync = false
        win32KeepForeground = true
        switchCorners = none
        switchCornerSize = 0


There be dragons

Here is a good one... I happened to be checking one of my yahoo addresses which I rarely use and noticed the following message from 'Blizzard'.

Language is off. You can tell from the first sentence that message is suspicious. Plus, I had never given my yahoo address to Blizzard, so clearly this was a scam. If you hover over the first link, it really points to the Blizzard but the second one was pointing a phishing site they want the person to go. Chrome actually recognizes the site as warns you about it.

Here is the lesson: NEVER click any link without checking the actual URL it's pointing to by looking at the status bar.


We have already noted that you are trying to sell your personal World of Warcraft account (s). 
Terms of Use 

It will be ongoing for further investigation by Blizzard Entertainment's employees. 
If you wish to not get your account suspended you should immediately verify your account ownership. You must complete the steps below to secure the account and your computer. 

We now provide a secure website for you to verify that you have taken the appropriate steps to secure the account, your computer, and your email address. Please go to this site and follow the instructions: (points to the site in the picture. Link removed)

We will contact you with further instructions once we have received and processed your submission. If you do not receive a reply within 48 hours of submitting this form, please resend it from the address listed above. 

Please be aware that if unauthorized access to this account, it may lead to further action against the account. 


Game Master Dunarthra 
Customer Services 
Blizzard Entertainment

Update: I actually saw at least 5 different variations in my e-mail box all trying to entice me to phishing sites. Some of the subjects are below:
Mists of Pandaria Beta Test Invitation WoW MoP Beta
Mists of Pandaria Beta Test Invitation
World of Warcraft Mount: Heart of the Aspects (lol on this one)

Fixing pepper flash issue(?) on latest chrome

 The latest version of Chrome (v22.0.1221.0 - I am on dev-m channel) causes some playback issues with flash videos on my pc. Top part of the video is cut diagonally and keeps on flickering. Here is the link to my bug report.

Screenshot shows how it looks on my screen.

Possible Cause:
The new 'Pepper Flash', result of collaboration between Adobe and Google is supposed to be more secure. Latest release of Chrome has it set as the default flash player on my Windows 7 machines and it seems to be the cause of this issue.

Until a fix is available, disabling Pepper Flash seems to be an easy solution.
In my case, typing chrome://plugins showed that I had 3 Flash plug-ins:

  • The new Pepper Flash plug-in
  • The built-in Flash plug-in that comes with Chrome
  • And the Flash plug-in installed separately for IE and other browsers. 

Clicking the details on the right side of the screen and checking the "disable" link under Pepper Flash seems to have fixed the issue for me.

Note: I still see the same diagonal line if I hover over a link item on the page that would normally overlay a menu, so I am actually not so convinced that this is a PepperFlash issue as I originally suspected. See Chromium discussions for further details (link above).


Upgrading Android Nexus S to Jelly Bean 4.1.1

It's been quite a while since I embarked on getting my Nexus S upgrade to ICS early. I blogged that journey here. For the last 1.5 months I am carrying both my Nexus S and an iPhone 4S, and frankly I prefer using iPhone for battery life if not for anything else. My favorite activity on Nexus S is tethering my iPad Wi-Fi during my work commute. Anyway, iPhone 4S vs Android 4.x Nexus S discussion is for another day.

Today, Google released 4.1.1 for Nexus S (T-Mobile) and it's officially available if you want to download the binaries:

I downloaded the zip file and renamed it to (renaming is optional)
Then connected phone to my pc and transferred the to SD Card
Powered off the phone
Pressed Power + Volume Up keys to bring the boot menu
Selected recovery
...and wait for it...

No cigar! I got the infamous red triangle with a black  exclamation mark on a green Android picture.

Apparently, one of the updates from 4.0 to 4.0.4 changed the boot files I had for custom booting before.

Interestingly, I found out that I was able to bypass this screen if I keep on trying to press Power + Volume UP key a couple of times (usually the 3rd was the charm).

I then got into the recovery mode where I was presented with the option I was looking for:
"apply update from /sdcard" (to select the option use Power button. Volume up/down to go up/down)

After selecting, install started and ...

-- Install /sdcard ...
Finding update package...
Opening update package...
Verifying update package...
Installing update...
Verifying current system...
assert failed: apply_patch_space(16570800)
E:Error in /tmp/sideload/
(Status 7)
Installation aborted.

failed :(

At this point, I thought I might be low on sdcard space and perhaps that was causing this issue. I did some clean up and free space jumped up from 700MB to 5GB. Unfortunately, the next attempt did not result in anything different.

So tried a couple of other options, all failed:

  • Wiped cache partition... 
  • Wiped cache partition + Wiped data/factory reset (which means you lose everything on the phone!)...
  • Wiped SDCard...

At this point, I started looking at Nexus S XDA forums. People suggested using ClockWorkMod to patch. I used it before, it's a great tool but instead I chose to use this trick to get official OTA update from Google. Steps (I changed the order a bit) are as follows:

  1. System settings
  2. Apps > All (If "all" is not displayed, pull the top bar that reads "running" to the left)
  3. Google-Service-Framework
  4. Force stop
  5. Clear Data
  6. Go to Homescreen
  7. System settings
  8. About Phone
  9. System updates (last time of update checking should be before 1970)
  10. Check now
  11. if you do not get the update, go to step 1.

After the second try I got offered the update. Rest, as they say, is history:

I am dying to try this trick, which is clearly quite harmless, on my wife's nexus S but she explicitly prohibited me from installing Jelly Bean / 4.1.1 until I confirm that it had been working without any hiccups on my phone for about a week :)

Now it's time check out  Highlights and read what's new?


New Features in PowerShell 3.0

MS PowerShell Team blogged about some of the upcoming features in PowerShell 3.0 here.

I think there are some terrific improvements in the syntax that will make PowerShell more consistent or less unpredictable, if you prefer.

In my tests, some of the features are not yet fully working on Windows 7 but once the final release is out, current issues should go away.

Improved Custom PSObject Creation
One of the cool changes is about creating a custom object. It was already improved in Version 2.0 and now it got even better. Here is a common way of creating one:

Powershell 1.0

$MyCustomObject = New Object PSObject
$MyCustomObject | add-member NoteProperty name "Adil"
$MyCustomObject | add-member NoteProperty lastname "Hindistan"

PowerShell 2.0
$MyCustomObject = new-object PSObject -Property @{name="Adil";lastname="Hindistan"}

PowerShell 3.0
$MyCustomObject = [PsCustomObject]@{name="Adil";lastname="Hindistan"}

So basically you are now simply casting 'PsCustomObject' type like any other.

Local Variables with $using
Another feature I liked seeing is about using local variables. I had written a function a while ago to remove an application given its uninstall string. I needed that to remove unwanted VNC installations from an environment.
It goes something like this:
function remove-app {

    ## E.g. $vnc |%{ remove-app $_ '"C:\Program Files\RealVNC\VNC4\unins000.exe" /SILENT' }, where $vnc holds list of machines

    param ($computer="$env:ComputerName",
       [string]$UninstallString   ## Use QuietUninstallString when possible

    $result="Encountered an error, sorry!"
 if (test-connection $computer -count 1) {
     "Pinging $computer successful"
     if ($UninstallString) {

          ## we have to use param and argumentlist in the script block to pass variable to the remote computers

      $result = invoke-command -computer $computer { param($UninstallString);&cmd /c $UninstallString} -ArgumentList $UninstallString

          ## New in PowerShell 3.0:

          ## $result = invoke-command -computer $computer { &cmd /c $using:$UninstallString}



 } else { "Pinging $computer failed"}



You see that invoke-command line over there? I had to use $UninstallString 3 times in that command to pass it to the remove machine. This got much simpler with PowerShell 3.0 with the addition of "$using:" :

$result = invoke-command -computer $computer { &cmd /c $using:$UninstallString}

By the way, I used that function together with another here that returned a list of uninstall strings from the registry:

function get-appsreg {

    param ($computer="$env:ComputerName",



    $result="Encountered an error, sorry!"

 if (test-connection $computer -count 1) {

        if ($product) {

            ## we have to use param and argumentlist in the script block to pass variable to the remote computers

   $result = invoke-command -computer $computer { param($product);get-itemproperty hklm:\software\microsoft\windows\currentversion\uninstall\* |?{$_.DisplayName -match $product}|Select DisplayName,UninstallString,QuietUninstallString } -ArgumentList $product

        } else {   

   $result = invoke-command -computer $computer { get-itemproperty hklm:\software\microsoft\windows\currentversion\uninstall\*,hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall\* |Select DisplayName,UninstallString,QuietUninstallString } -erroraction silentlycontinue

Count and Length
With PowerShell 3.0 "count" and "length" properties are also becoming universal. I.e. even if an object does not have these properties currently, you will be able to use them in the new version.

Similarly, every object is getting 'indexing'. So, using the custom object example above, it will be possible to use the following syntax:

$MyCustomObject[0]   ## returns the object itself. Other indexes return nothing

It does not look useful really but it does improve the consistency!


Must Read This!

Internet is a beautiful place. Sometimes, you hit an old article that makes you feel like you found a  treasure, it may teach you a great life lesson.

For me, the best way to get back to them is simply link to them in this blog. Here are a few and I intent to update this post with such findings in the future:

  • Submarine - Paul Graham [2005]: This article is about PR firms and how 'news' get planted.
  • Nastiness - Tim Bray [2009]: I admired Tim Bray ever since reading up his take on XML specification, which he co-edited. Here, he tells a story about some nastiness that went on in a Ruby conference, which is totally insignificant, and gives us his recommendation on when to apologize, which is golden!


Do typos bother you?

Typos do bother me. I guess that's because when I am reading something, they hit (and hurt) my eyes pretty quickly (so if you are seeing typos on this blog, you know why: I do not read my own blog :) and it sort of gives the impression that the person who was writing it may not have paid enough attention to the piece, somewhat decreasing the over all value of it.

Anyway, today I was looking at my Google Reader RSS subscriptions and noticed a new article from Microsoft KB here: "Configuring WinRM for HTTPS" (click on pic above to see the actual page).

There is nothing special about this KB other than that it is on its 8th revision (wow!) as of May 17, 2012, yet apparently information was printed without going through a spell-checker. In fact, there is a note at the bottom of the article which prepares us for such typos:

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice.

I sent a message to them using the feedback system at the bottom. I wonder how long it will take them to correct it.

Update: 2012-06-29
Almost the same story but this time, it's about an Apple Knowledge Base article. Here is a very common typo in article about 'Apple Thunderbolt to Gigabit Ethernet Adapter: FAQ' (HT5309) that was last modified 10 days ago (click on picture to see the actual page).

Unfortunately, there is no feedback mechanism on the page to tell Apple about this.
Oh, Microsoft page is still not corrected. I guess they are not reading the feedback.


Uninstalling Microsoft Security Essentials from Command Line

Recently, I came across a situation where I wanted to replace Microsoft Security Essentials on a couple of computers. The first question was how to uninstall Microsoft Security Essentials from command line. So, I looked for an Uninstall String in the registry:

PS Z:\> gp HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |? {$_.DisplayName -match "security" } | select DisplayName,UninstallString |ft -auto

DisplayName                              UninstallString
-----------                              ---------------
Microsoft Security Essentials            C:\Program Files\Microsoft Security Client\Setup.exe /x
Microsoft Baseline Security Analyzer 2.2 MsiExec.exe /I{08C3441C-4FAF-48D3-A551-70DD6031734F}
Microsoft Security Client                MsiExec.exe /I{42738DB0-FC3E-4672-A99B-9372F5696E30}

First one was promising. So, I started the PowerShell from an elevated command prompt to avoid UAC, and typed the following:

PS Z:\>$UninstallString='"C:\Program Files\Microsoft Security Client\Setup.exe" /x'

Followed by:

PS Z:\>Invoke-Command { param($UninstallString);&cmd /c $UninstallString } -ArgumentList $UninstallString

I did not yet pass a computer list with -computer parameter. This command did start the uninstall "wizard".  I did not want to baby-sit the installation, in other words, I wanted to run the uninstall silently, so I started looking at other parameters that would do it and found out that, "/s" is the parameter I was looking for. The command below took care of the uninstalls silently:

PS Z:\>$UninstallString='"C:\Program Files\Microsoft Security Client\Setup.exe" /x /s'
PS Z:\>Invoke-Command -computer (gc .\computers.txt) { param($UninstallString);&cmd /c $UninstallString } -ArgumentList $UninstallString

Where computers.txt contains the list of machines.
Update - 2012-08-08: PowerShell 3.0 has an updated syntax, that simplifies this code greatly. See this post:


More funny comments...from Microsoft

After discovering some funny comments from Dell folks (see previous post), I looked at some other folders in the CD and came across what seemed to be manifest files used possibly used by Microsoft upgrade scripts, User State Migration Tool (USMT) and Migration Wizard (MigWiz).

These files reside in the Dell's Windows 7 Pro CD that came with Dell Vostro CD. Specifically, under \sources\dlmanifests folder:

OK, that's a confession there! And why would not you uninstall reg keys cleanly?

I am just wondering who is (s)he talking to here...

Hmm, so who is this mollybro? I see a 'mollybro' profile in MSDN, with a reference to an SMB related resource. Same person?

OK, enough with this Saturday-Night Geek Entertainment. Here is the last one:

Nobody can say (s)he is not honest!


Funny Comments in Dell's IE Branding Script

I was looking at the contents of a CD that came with a new Dell Vostro PC (oh, don't even ask why).
The following folder initially seemed interesting:


But there was not much in there other than what seemed like an Internet Explorer branding script:

I was about to check the other folders, but wanted to checkout TextAppend.vbs and then noticed some interesting comments:

I like the --fail comments. Blogging for entertainment value :)