Archive

Archive for April, 2010

Using PowerShell and the DirectorySearcher class

April 9th, 2010 jvallery No comments

I needed to locate the LDAP distinguished name of an individual user account in a remote domain via PowerShell.   Assuming your script is running on a box that is part of a domain that has a trust to the remote domain we can do this by running a query against Active Directory with LDAP.

By using the DirectorySearcher class we can build complex LDAP queries to find objects in Active Directory.   With this information you can do all kinds of fun scripting things.

Here is a sample script:



#Specify the search criteria
$samname = "jasonv"
$domain = "dev.lcl"

#Get a list of domains in the forest and grab the DN of the one matching the above parameter.
$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$domain = $forest.Domains | ? {$_.Name -eq $domain}
$domainDN = $domain.GetDirectoryEntry().distinguishedName
Write-Output  "Found the remote domain, the full LDAP distinguished name is $DomainDN"

#Create an LDAP searcher object and pass in the DN of the domain we wish to query
$Searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"LDAP://$domainDN")

#Pass in the ceriteria we are searching for.
#In this case we're looking for users with a particular SAM name.
$Searcher.filter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName= $samname))"
$results = $Searcher.Findall()

#Loop through the results
Foreach($result in $results){
    $User = $result.GetDirectoryEntry()
    $userDN =  $user.DistinguishedName
    Write-Output "Found a user matching with the distingused name of $userDN"
}

Why I don’t recycle paper

April 8th, 2010 jvallery No comments

I had a run in with a co-worker today who was upset that I hadn’t placed a couple sheets of paper in the recycling bin instead opting for the trash. I do this on purpose and I thought it would make an interesting blog post to explain why.image

The primary goal of recycling is to minimize the impact of our consumption on the environment. The basic argument however as to why we recycle usually goes along the lines that as humans we should recycle our consumables so that they can be used again without depending on a natural resource to replenish them. The thing that the vast majority of folks fail to realize is that in many circumstances that statement is either incorrect or actually in opposition of the goal behind recycling.

To dig a bit further we need to look at recycling on a case by case basis for the material in question. Typically recyclable materials are broken down into the following types:

Paper

The source of paper is wood which obviously comes from trees. Those trees are typically purpose grown to provide paper. There are large swaths of forest that were planted specifically by the various providers of wood in order to meet the demand we have on it. In this very real sense wood is not a natural resource it is actually a crop. There are more trees today in the United States than when the original settlers landed on this continent centuries ago. Why? Because we need them. It’s basic supply and demand economics in that as this country’s appetite for wood increased more trees were planted.

The cost, both monetarily and ecologically, associated with producing a recycled sheet of paper exceeds the cost of producing one from new wood. This is because for recycled paper you have additional steps in the production process. You must collect the recyclables, sort them, haul them to a processing facility, separate the paper from other debris and items, grind the paper into pulp, bleach it (using harmful chemicals), and then produce a sheet of paper. All of these extra steps use energy which today is delivered in the form of fossil fuels. The diesel that the truck to haul the recyclables burned, the coal to run the power plant which provided the electricity to process the paper, etc. With new paper there is of course still energy expended but several studies indicate that the amount used for a recycled piece of paper exceeds the amount needed for a new sheet of paper.

The other benefit you have of using new paper is that you’re planting trees. By consuming more paper you’re asking the paper manufactures to plant more trees on your behalf. During the 25-30 years that the tree spends maturing to be ready for harvest it is busy eating carbon dioxide and producing oxygen. If you subscribe to the greenhouse gas and global warming theories you’re now demonstrably reducing the carbon dioxide levels in the atmosphere by not recycling paper.

This is why I think, and a lot of other folks do as well, that you’re actually hurting the environment more be recycling paper. Throw it in the trash and we will grow more trees.

If you think I’m alone look for yourself

Plastic (biodegradable) –

These plastics were designed specifically to decompose quickly in sunlight and the soil. They can sometimes even be used in compost. Again, it makes much more sense to throw these in the trash than to recycle them if you’re not a composter. The trip to the landfill uses much less energy than the equivalent required to process this in a recycling facility.

Plastic (Non-biodegradable) –

Recycle these!!!!! Non-biodegradable plastic is the single item that the average consumer throws away which has the largest negative environmental impact. It can sit around in landfills for centuries. If it can be recycled into something useful (which in this case is often a reuse) that is the best possible outcome.

Glass –

I’m on the fence about glass. The information is inconclusive. Glass is obviously derived from a natural resource (silicon) that has a finite supply. If you’ve ever been to a beach though you’ll recognize that even though it is finite it is also nearly inexhaustible. I don’t have a strong opinion one way or the other and will reserve judgment until more concrete studies are done that look at the cost/benefit of recycling glass.

Aluminum –

You should certainly recycle aluminum as the source is primarily bauxite. Since bauxite is a mined natural resource we can significantly limit our dependency by recycling. This same reason is why you can actually sell your aluminum soda cans back for cash. It’s much more efficient to recycle than to mine new bauxite and produce aluminum.

Other metals –

It really depends on the metal but like aluminum the source was most certainly a mined mineral. I recommend recycling these items (soup cans, etc).

My impression of the iPad after 72 hours

April 6th, 2010 jvallery No comments

In follow-up to my earlier post I wanted to share my thoughts now that I’ve actually used my iPad during my day to day routine.

I’m still very pleased with the hardware.   The size is just about perfect for taking to a meeting or sitting on the couch.  I haven’t yet traveled with it but will have that opportunity next week.   I expect it to be great for use on the plane.

When using the Apple case I find that sitting the slightly raised iPad down on the table to be at the perfect angle for typing.

The battery life is great.   While I had my initial concerns about the inability to charge the iPad with anything but the included wall charger, that hasn’t proved to be as big of an issue as I expected.   In reality I haven’t dropped below 60% battery usage after 2 days of fairly heavy  usage.  I just plug it in the wall charger at night before I go to bed.   I still think they will need to address the issue but it’s not bothering me.

The browser is absolutely fantastic.    Aside from the obvious and unfortunate omission of flash support it is actually a really capable device for basic web surfing.   Initially I was concerned that there is no native Facebook application that leverages the capabilities of the iPad.     I’ve actually found using the full web version of Facebook to be great thanks to the screen real estate and the capabilities of Safari.   I would argue that thanks to the touch interface surfing the web might actually be better on the iPad compared to a traditional PC.

I really can see the potential to lower my dependency on my laptop for basic tasks.   In example, I’ve found it to be particularly useful for basic emailing and calendar activities.   Contrary to my iPhone it is actually pretty easy to type on, copy/paste, etc.   I don’t mind writing an email on my iPhone in a pinch but it’s not something I would do regularly.   With the iPad it’s actually a much more pleasurable experience.

I’ve also been enjoying a few additional applications:

 

kindle

Kindle for iPad – To correct my earlier post, it turns out there is a Kindle app for the iPad.   I’m happy to see this since I have a decent investment in ebooks from Amazon.  The UI is fine, but not as polished as Apple’s iBook.


evernote

Evernote for iPad  -  I’m already a big user of Evernote so the iPad version was very welcome.   I used this in meetings yesterday and today to take notes.   It’s great to sit the iPad down on a conference table to keep track of what is being discussed.   I think this use case has the potential to be the single greatest “killer app” to bring the iPad to the enterprise.

twitterific

Twitterific for iPad -   I had been using Tweetie 2 on my iPhone as of late for interaction with twitter.   Based on the great reviews of Twitterific for iPad I gave it a shot.    This is a much better UI for interacting with twitter, thanks to the additional screen real estate.  I’m hopeful that the folks behind Tweetie will come out with an iPad version because there are some features missing in Twitterific.   I particularly enjoy the location aware components of Tweetie including searching for “tweets near me” and the inclusion of google maps links when a tweet includes lat/lon information.

Categories: Reviews Tags: , , , ,

My first impression of the iPad

April 5th, 2010 jvallery 1 comment

I’ve had the iPad now for 24 hours so I thought I’d write up my first impression.   I’m no longer the Apple fan boy that I once was.   I’m a bit more cynical about Apple these days so when I purchased my iPad I did it with eyes wide open.  I opted for the cheapest model available which is the 16GB version without 3G.

Out of the box the iPad feels very nice to hold.   It’s got a pleasant heft to it and feels very solid.  The weight feels very evenly distributed so it is easy to hold no matter what orientation.  Upon opening the box you’ll find the iPad, a standard iPod cable, and a wall charger.   There are no headphones included which was a bit of a disappointment for me.

The iPad came fully charged which was a nice touch, however in order to begin using it you must connect it to iTunes.   While Apple offered to do this in the store for me I declined and activated it when I got home.   This step seems a bit strange to me since there is no mobile phone service to activate.   I understand the rationale for the iPhone but I don’t see the need for the iPad.

After plugging the iPad into my computer for it to activate with iTunes the first thing that caught my attention is that in the upper right hand corner of the screen where the battery indicator is at said “Not charging”.   It turns out that there is an issue with the charging capability of the iPad currently and it can only be charged with a Mac computer or the included wall charger.   My Dell desktop apparently was insufficient to give this thing juice.   Curious, I took my iPad out to the car and plugged it in to see how it would behave in the car.   Sure enough, no charge love there either.    I expect this to be fairly inconvenient if not fixed soon.   I charge my phone almost exclusively at my desk and in the car.   I can get a sync and a charge at the same time this way.

I brought the iPad back inside and hooked it up to my PC again to let it sync with iTunes.  You have all the same sync capabilities as the iPhone so I won’t cover that in detail.   Given that I only purchased the 16GB version it filled up very fast.    The sync copied over most of my iPhone apps so my first experience  with 3rd party apps were the upscaled iPhone ones.

After the sync I opened up Facebook for iPhone to see how it worked.  It’s great that the iPad can use iPhone apps but in reality I can’t say that I would really want to.   For example take a look at this screenshot of Facebook scaled up to the “2x” mode.  As you can see the text becomes very grainy and it just looks plain awful.

IMG_0002

In comparison I downloaded the latest version of NetNewsWire from NewsGator which is an iPad native application and it looks simply stunning (notice the “Not Charging” in the upper right).

IMG_0004

There are a number of great apps similar to NetNewsWire that were available at lunch.   The much anticipated Netflix is probably my favorite.   I was able to stream a movie live from Netflix without any hiccups over my wifi.   It was a very enjoyable experience to watch a movie this way and I’m looking forward to using that extensively on my many work trips in the hotel.

I was a bit surprised that Apple has cut out some of the applications that ship with the iPad compared to the iPhone.   The stocks, weather, calculator, and voice memo applications are all suspiciously missing.

Purchasing content with the app store is just as easy on the iPhone.   The cost of applications seems to have gone up dramatically.   Many apps are looking at $9.99 price tags which seems a bit high to me.   I’m sure the market will adjust as both more applications and iPads are on the market.

Reading books via iBook is very pleasant.   I’m particularly impressed with the page turn effect.   I know it’s just eye candy but I still love it.  I previously owned a kindle so I’m hopeful that Amazon will release a kindle application (and that Apple doesn’t block it) similar to the one they have for iPhone.    I have a several titles I’ve already purchased in the Amazon store and I’d hate to not be able to access those on the iPad.

The last comment I’ll make is that 16GB is surprisingly little.  When I opted for the small version I didn’t really expect to load it down with media.   I expected that most of the time I would be using Pandora/Netflix for movies and music so storage wouldn’t be an issue.   It turns out many of the iPad applications are surprisingly large.   For example the “Real Racing HD” game comes in at a whopping 171 MB.

Categories: Reviews Tags: , ,

Using powershell to set SSP profile properties

April 1st, 2010 jvallery No comments

I recently put together a powershell script that can be used to update a profile property of all of the users stored in the SharePoint SSP.  At NewsGator we use a boolean property field to indicate if a particular part of our product has been activated or not.  There are some cases where this boolean flag needs to be reset for all users. To do this I put together a simple powershell script to reset this value for all users.

This could easily be adapted for other users so I thought I would post share it.

###########################
# "Configure Settings"
$SSPName = "SSPAdmin"
$MySiteUrl = "http://mysite/"
$propName = "newsgator-x-onboarded"
$propValue = "true"
###########################

#Load the SharePoint assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")

$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSPName);
$UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
$enumProfiles = $UPManager.GetEnumerator();
"Total User Profiles available:" + $UPManager.Count
$count=0;

#Loop through the SSP entries and update the property
foreach ($oUser in $enumProfiles)
{
    $count = $count + 1;
    $u = $oUser.Item("Accountname");
    Write-Output "($count):  Setting '$propName' to '$propValue' for $u";
    $oUser[$propName].Value = $propValue;
    $oUser.Commit();
} 


Activating features in bulk on the MySite with PowerShell

April 1st, 2010 jvallery No comments

I recently came across a client who needed to activate a couple of features on their MySites in batches.   Given that they have a significant number of MySites already created we needed to find a way to stage the deployment of the new functionality that the features offer.   I put together a PowerShell script that iterates through the SSP looking for users who:

  • Have a MySite
  • Either one of both of the required features are not currently active

For each of the users that match the above criteria both of the features are activated. A counter is incremented and once we reach the desired number of users for the batch the script exits. When we are ready to process another batch the script effectively picks up where it left off since we’re skipping the users who are already activated.

You could then have the execution of this script automatically executed on a regular basis during low utilization hours. Eventually everyone will have the features activated and the new functionality deployed. You could continue to let the script execute to catch any new users (if you decide not to staple the features like we are).

For others looking to do something similar I’m posting the original script in its entirety.


###########################
# "Configure Settings"
$SSPName = "SSPAdmin"
$mysiteurl = "http://mysite"
$ngsite_feature_id = "6a91335c-5ecc-4afc-aa68-14d73afbb1bc"
$webpart_feature_id = "5174F049-99D9-4d68-96E0-93AB2AE1C7BC"
$userCount = 500
$stsadm = "$env:programfiles\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE"
###########################

#Load the SharePoint Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")

#Create the SSP objects
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSPName);
$UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);

$enumProfiles = $UPManager.GetEnumerator();
"Total User Profiles available:" + $UPManager.Count
$count=0;

#Loop through every user who has an entry in the SSP
foreach ($oUser in $enumProfiles)
{
    #Get the username for the user
    $u = $oUser.Item("Accountname")

    #How many have we activated?  If more than $userCount above stop processing
    if ($count -ge $userCount) {
        Write-Output "Okay, we're stopping for now because we've activated for $userCount MySites"
        break
    } else {

    #Does the user have a MySite?  If so continue
    if ($oUser['PersonalSpace'].Value -ne $null) {
        #Create an SPSite (Site Collection) and SPWeb (Web) object for the given users MySite
        $siteurl = $mysiteurl + $oUser['PersonalSpace'].Value
        $spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
        $spWeb = $spSite.OpenWeb() 

        #Let's check to see if either of the features we want to activate are currently activated.  
        #If not we should activate them.   Remember that the NewsGator Site Feature is "site" scoped thus we use SPWeb
        #The web part feature is Site Collection scoped so we have to use SPSite
        if (($spWeb.Features[$ngsite_feature_id] -eq $null) -or ($spSite.Features[$webpart_feature_id] -eq $null)) {

            #Execute STSADM -o activatefeature to activate the NewsGator Site Feature for this user, if it fails capture that and stop execution of the program.
            $sResult = &stsadm -o activatefeature -id $ngsite_feature_id -force -url  $siteurl
            if(!($sResult -like "*Operation completed successfully*")){
                Write-Host -ForegroundColor "red" -BackgroundColor "white" "Activate of site upgrade feature failed for $u on $siteurl : `n $sResult"
                break
            }

            #Execute STSADM -o activatefeature to activate the Webpart deployment feature, if it fails capture that and stop execution
            $sResult = &stsadm -o activatefeature -id $webpart_feature_id -force -url  $siteurl
            if(!($sResult -like "*Operation completed successfully*")){
                Write-Host -ForegroundColor "red" -BackgroundColor "white" "Activate of mysite web parts feature failed for $u on $siteurl : `n $sResult"
                break
            }

            #increment the count and output a status
            $count = $count + 1;
            Write-Output "($count):  Features activated on $siteurl for $u succesfully";
        } else {
            Write-Output "Skipping $siteurl for $u as they are already active."
        }
    } else {
        Write-Output "Skipping $siteurl for $u as they do not have a MySite."
    }

    #Clean up our objects to prevent a memory leak
    $spWeb.Dispose();
    $spSite.Dispose();
    $siteurl = $null;
    }
}