Thursday, August 16, 2012

Powershell - Get bitlocker keys from AD

Today I was aksed to help write a script to get a list of all the computers in our domain and show which ones had their bitlocker keys backed up to AD.

I googled around to find where in AD the information was stored, and proceeded to write this beauty of a script.  Feel free to modify as you see fit and let me know if you found it useful.

# Load AD tools
import-module ActiveDirectory
## Initialize Variables
$searchBase = "ou=Workstations,dc=mycompany,dc=com"
$RecoveryInfoPresent = 0
$MyCount = 0
$MaxCount = 5000
##Inform the user what is about to take place
Write-Host "Searching " $searchBase " for computer accounts with bitlocker keys.........."
Write-Host ""

##Create Table - ResultsTable
$ResultsTable = New-Object system.Data.DataTable "ResultsTable"
$col1 = New-Object system.Data.DataColumn ("HostName", [string])
$col2 = New-Object system.Data.DataColumn ("CanonicalName", [string])
$col3 = New-Object system.Data.DataColumn ("RecoveryPassword", [string])
$ResultsTable.columns.add($col1)
$ResultsTable.columns.add($col2)
$ResultsTable.columns.add($col3)
$computers = Get-ADComputer -Searchbase $searchBase -filter *
foreach ($computer in $computers)
{
    $RecoveryInformation = get-ADObject -ldapfilter "(msFVE-Recoverypassword=*)" -Searchbase $computer.distinguishedname -properties canonicalname,msfve-recoverypassword

 ##Loop through as their may be multiple saved
 foreach ($RecoveryInfo in $RecoveryInformation)
 {
  $output = $ResultsTable.Rows.Add($computer.name, $RecoveryInfo.canonicalname, $RecoveryInfo."msfve-recoverypassword")
  $RecoveryInfoPresent = 1
 }

 if($RecoveryInfoPresent -eq 0)
 {
  $output = $ResultsTable.Rows.Add($computer.name, "", "")
 }
 else
 {
  $RecoveryInfoPresent = 0
 }

 #Loop protection
 $MyCount = $MyCount + 1
 if ($MyCount -ge $MaxCount)
 {
  break
 }
}
##Write txt/csv file
#$ResultsTable | Out-File bitlockerinfo.txt
$ResultsTable | Export-Csv bitlockerinfo.csv -notype

##Inform the user that processing is complete
Write-Host "processing complete"

Tuesday, August 14, 2012

Going back to WSS 3.0 from MOSS 2007

Back in 2009 I switch departments at the company i work for and was placed in charge of the sharepoint farms.  i had been getting a lot of people complaining about an inability to edit user information within site collections on our WSS farm.  Normally, you would just click a users name in the top right of the screen, click My Settings, and then edit the information about yourself in the text boxes that would appear.  Intead, only the readonly account field was displayed in edit mode.  If I created a new site collection, the issue was not reproducable, but on most existing sites i was able to reproduce.  This cause me to scratch my head and I started googling...  a lot!  Try as i might, i couldnt find anyone else having this issue.

Read on to find out why and how I fixed it.....

Right before I was in charge of our SharePoint farms a coworker of mine decided to attach a WSS 3.0 content database to a MOSS 2007 instance in order to gain some backup capabilities of some third party software.  Problem was, the DB was still attached to WSS 3.0, and the organization never had any interest in using the paid version of SharePoint for that particular farm....  I quickly proceeded to detach the database from the MOSS farm, but the damage was already done and too much time had passed to make restoring from backups a viable option.

Any site collection that was in the database at the time the DB was attatched to MOSS was upgraded to a new schema that affected the user information for each site collection.  Newly created site collections functioned normally, but all the old site collections were broken: meaning that all user information on the site was read only.  This did not go over well with some of our users (some external to our company).

I literally tried everything i could think of to fix the broken sites, including a support case to Microsoft.  It made its way really far up the chain until months into the case the senior engineering staff i worked with gave me two solutions:  live with it, or manually edit the DB each time a user wanted to change a property.  Wow.  Really?  MS has no db scripts to reverse the changes made?

Backing up and restoring the site still left the site in a bad condition.  Attempts at a fresh new farm did nothing to help the cause either, as the site collections were themselves to blame.  I worked this problem for months and the best solution i could come up with was to rebuild the problem sites by hand or just leave them broken.

We have a LOT of site collections, and have lived with this issue on the old sites for years now.  Our solution has been to migrate by hand all the content on the site to a new site (losing all versioning, last modified by, created by, etc data) in order to fix the problem when the userbase of that site complaned loudly enough.



Fast forward a few years, and well last week one of the last few sites (there are only about 26 bad sites left) needed to be upgraded.....  but it was HUGE!  I deceded to try my hand at hacking the backup files to see what i could manually change in order to get the backup/restore to succeed.  I'll spare you the details of everything i tried, but i wasnt able to get that to work either....

Cue the best solution i have come up with thus far:  In all my attempts I tried something i never tried before: export/import.  If i performed a basic export, and a basic import, all the files and site structure moved over, and the user information list worked again, but the metadata on who touched each file didnt persist.  After a bunch more attempts, this is the best i was able to do:

stsadm -o export -url https://site.mycompany.com/sites/brokensitecollection -filename d:\brokenSiteCollection.bak -quiet -versions 4
stsadm -o import -url https://site.mycompany.com/sites/fixedsitecollection -filename d:\brokenSiteCollection.bak -quiet -includeusersecurity -updateversions 2

by exporting with versions and NOT including user security, the brokenness of the site was not carried over.  by importing WITH security the user information of who last edited a file and all ther version information still transfered over.  The only thing missing was the actual permissions to the site, which given how much work i used to have to do, this is not a big deal to finish out by hand.


So, moral of the story:  If you find yourself in this unique situation (I hope you dont), use the export/import command with the switches indicated above to get the site in a proper state again.

Wednesday, May 30, 2012

WSS 3.0 Search Issues and SSL

So today I had to battle some issues with WSS 3.0 search.  (yeah i know, its sad that we still have an environment running code that old)

The issue was that the search service went belly up while i was away on vacation.  It was still running, but no search results in the application.  After trying just about everything I could find online, I had an epifany of what might have gone wrong based on the errors i was seeing in the logs within the 12 hive.

Somehow the root certificate for our wildcard ssl cert was no longer trusted on the box.  After retrusting the cert within the mmc snap-in certificates, search finally worked.

I am writing this blog post merely for my own knowledge of some of the steps i took to troubleshoot the problem should something in the future arise.


Check the obvious
  • Is search actually running? 
    • Operations --> Services on Server --> Windows SharePoint Services Search
  • Make sure the content DB is using the search server
    • Application Management --> Content Databases --> Click your content db --> Pick the search server.  Sometimes you may have to set the content db to offline, hit OK, then put it back online to get things running.  Dont worry, no downtime is percieved by this.
  • Force a full crawl
    • stsadm -o spsearch -action fullcrawlstart

Then check the event viewer and the logs in the 12 hive for clues.

Another useful check, and the main reason i wrote this post is the following queries against the search DB.   These will give you an indication that search is working and if errors are being thrown the first query will show them to you.


select msscrawlurllog.lasttouchstart as Time, msscrawlurllog.displayurl as URL,msscrawlurllog.errorid as Error, msscrawlerrorlist.errormsg as Description
from msscrawlurllog
join msscrawlerrorlist on msscrawlurllog.errorid = msscrawlerrorlist.errorid
where msscrawlurllog.lasttouchstart >= DATEADD(mi, -5, getdate())
order by msscrawlurllog.lasttouchstart desc

SELECT [CrawlID],[RequestTime],[Status],[StartTime],[EndTime]
FROM [MSSCrawlHistory]
order by starttime desc

SELECT [HostID],[HostName],[SuccessCount],[ErrorCount],[WarningCount]
FROM [MSSCrawlHostList]

Wednesday, May 2, 2012

Powerview Icon in SharePoint 2010

So you got PowerView installed and configured for your SharePoint 2010 instance.  You finally have figured out how to create a data source and you create your first report in a document library.  You click save and return to said document library, only to find the hideous blank icon next to the report instead of the PowerView icon.



I can help you fix that, and its really easy!

On each of your WFE's (web front ends) make the following change:
  1. Verify that this file exists: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\ReportServer\16reportx_sp.gif
  2. Open C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\DOCICON.xml with your favorite text editor (Notepad++ is my favorite)
  3. Add the following line directly beneath the entry for rdl extensions:
    <Mapping Key="rdlx" Value="ReportServer/16reportx_sp.gif" />
  4. The final file should look something like this:
  5. Save your changes.
  6. Perform an IISReset.
Now, refresh you browser and you will see the PowerView specific icon.

 Hopefully this was a big help.  Leave a comment letting me know your experiences.

Thursday, February 23, 2012

My Custom Bed

A little over 4 years ago my wife and I decided to purchase a new bed, as we were waking up very sore on the free mattress we were currently sleeping on.  We had decided to go ahead and buy a very nice mattress, since we both thought at the time that if we spent a lot of money on a nice mattress it would last a long time.  $2400 and 4 years later i wake up more sore than when i was sleeping on the free mattress.

Over the past few months i have been doing a lot of research as to what our next mattress should be.  Our options:

Coil Spring
I knew if i went with another coil spring mattress, it would have to be considerably cheaper, since all spring mattresses appear to last about the same amount of time unless you buy a really cheap one.

Air
My father has one of the air based beds, the sleep by number, and my wife and i had the opportunity to sleep on it for a week.  I was not happy with how it slept, and very annoyed that the firmness changed at random each night, and the pump seemed to always cycle on and off.  The bed was basically falling apart as well.  A lot of research also led me to find out that they tend to have issues with mold growing between the air chamber and the foam topper that is placed on them.  Yuck.

Water
People still use water beds!  Kinda weird i thought.  Ive slept on water beds, but have never liked them.  We didnt give them much consideration at all.

Foam
There are a lot of foam beds out there, and after asking around to a lot of people I have found out that most people really like their foam beds.  They seem to last a lot longer than coil spring, and provide proper support during the lifetime of the bed.  They can be made from simple foam, memory foam, or synthetic/natural latex foam. 


Foam definitely seemed to be the way we wanted to go.  We started shopping for our next bed, but quickly discovered one thing: people like to charge a LOT of money for a foam bed.  As in $1500-$3000 and up for a Cal-King sized bed.  Being the engineer that I am, I about died seeing what they charged for a bed versus the cost of foam.  What could possibly make them so expensive?

NOTHING!

After exhaustive research, every single one of the beds was made of as little has 2 and as many as 7 layers of foam.  Some had 'bolsters' added to the bottom layer of foam, but most were just simple pieces of foam.

I started to research where i could buy each of the layers and was shocked at how cheap the foam can be obtained.  There are many websites that sell foam, and we decided to order ours from http://www.foambymail.com/ and http://www.amazon.com

We decided to model our mattress loosely off of the iComfort line by Serta, as we really liked the feel of their mattresses the best.  I would suggest before you embark on creating your own mattress, that you first try out some at your local mattress stores so that you know which mattress you are going to recreate.

We really liked Sertas gel memory foam, so we actually ordered their name brand foam.  How you ask?  A mattress topper!  We purchased the mattress topper from Amazon.com.  The rest of our mattress was standard foam that can be ordered from foambymail.com (FBM from now on).

This is the layout we went with:
2.5" Gel Memory Foam (Serta)
2.5" HD36-High Quality Eggcrate
2.5" LUX-High Quality Eggcrate
4" LUX-High Quality Foam

Shipping is free from FBM on orders over 100 bucks, and most amazon orders ship free and luckily the mattress topper was one of those items.  We placed our order and a week later we had all the pieces to make our mattress.

The foam comes highly compressed for shipping reasons, and per the manufacturer needs to be opened up ASAP in order to prevent it from permanently being deformed.

 Here is what came in the mail:

Foam in packaging.  Left package is both eggcrate, and the right one is the 4" lux.

Serta memory foam and cover.
The memory foam took the longest to regain its shape (4 hours) and had quite a smell to it.
Unrolling the memory foam.

Corners stayed smashed for a while.  Patience is key here.

Another shot of the corner after more time elapsed.

Almost there....

All the way expanded.  Amazing how small they can squish this stuff for shipping.
Here is the foam.  You can see how much larger it is after unpacking.
Before removing the plastic... 
And after....

Video of the foam expanding.


This is the final product.

And with a cover...

 


The smell is not as bad as when we first assembled the bed about 2 weeks ago, but it is still there.  The first few nights were rough, and I really think we probabaly should have let it air out longer before we started to sleep on it.  I'm expecting it to completely dissapate in another week.

Sleep
The most important part of this whole thing.  How are we sleeping on it?  GREAT!  We both love it and are getting absolutely great sleep. 

Test of time
We shall see how this bad boy holds up over time.  I'll keep this blog post up to date as time goes on with developments on if we still like the mattress and how it is holding up. 

Monday, December 19, 2011

Get XPATH of element in IE

Ever had the need to get the XPATH of an element and you are using IE.  Well, here is how you can:  Create a bookmarklet with the following javascript:

javascript:function getNode(node){var nodeExpr=node.tagName;if(!nodeExpr)return null;if(node.id!=''){nodeExpr+="[@id='"+node.id+"']";return "/"+nodeExpr;}var rank=1;var ps=node.previousSibling;while(ps){if(ps.tagName==node.tagName){rank++;}ps=ps.previousSibling;}if(rank>1){nodeExpr+='['+rank+']';}else{var ns=node.nextSibling;while(ns){if(ns.tagName==node.tagName){nodeExpr+='[1]';break;}ns=ns.nextSibling;}}return nodeExpr;}function getXPATH(){var currentNode=document.selection.createRange().parentElement();var path=[];while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf('@id')!=-1)break;}currentNode=currentNode.parentNode;}var xpath="/"+path.reverse().join('/');clipboardData.setData("Text", xpath);}getXPATH();

Bookmarklets are just a simple bookmark and you use the script as the url to the site instead of an actual url.  Hope someone else finds this useful.

The code above was adapted from http://functionaltestautomation.blogspot.com/2008/12/xpath-in-internet-explorer.html


Thursday, December 1, 2011

Random thought for the day... Programming in other countries

I had a random thought today while helping someone on my codeplex project (http://spdactivities2010.codeplex.com/):

What language is used to program stuff in other countries?  do they still use english to write their code?  I would assume javascript has to be, since it isnt compoled code, but what about compiled code such as c#?

Hopefully someone with internation experience will hop on here and enlighten me.

-R