Tuesday, March 4, 2014

View SharePoint Deployment progress


There are many instances where our team would deploy the SharePoint solutions through management shell and then opens the Central Administration in the browser to see the deployment progress.
It's much easier to just write a one liner to see the status instead.


Get-SPSolution SampleSolution | Select Last* | format-list

Friday, April 27, 2012

The Journey continues

It feels that every few seasons, I get the itch to blog again.  With the new job that I started at Sogeti USA, I think this is a great time to restart.  It did not take the company long to throw me into a rather complex development project.  In fact, that complexity is mostly due to SharePoint 2010 platform on which we have to deliver our product.  Therefore, I will ultimately have to rant or provide various workarounds over the next few months as I encounter. 

So, the journey does continue …

Wednesday, November 10, 2010

Inserting Records with Identity column table

So, recently, I needed to insert some static data manually within the staging environment.  I wanted to align the identity column values to be in ascending order but if there are any typos causing my inserts to be rolled back, then the identity values will have gaps because rollback operation does not preserve the next value for identity.  Therefore, using DBCC CHECKIDENT ('<schema>.<tbl_name>', NORESEED), I can find the current value of the seed, while using DBCC CHECKIDENT ('<schema>.<tbl_name>', RESEED,<last_used_value>) sets the identity to the last value. 

Sunday, March 7, 2010

I like to configure my VMWare Guests to manual startup/shutdown because I use the host for both as a management platform and a developer workstation.

To assist me with managing such environment, i use VI Tookit. Only 1.0 is compatible with VMWare Server 2.0, here. Install it on either x86 or amd64 box. Then, add a few lines of configuration to initialize the PSSnapin into your user’s PowerShell profile location:

Add-PSSnapin Vmware.VimAutomation.core
. "C:\Program Files (x86)\VMware\Infrastructure\VIToolkitForWindows\Scripts\Initialize-VIToolkitEnvironment.ps1"

Fire up PowerShell and you can do the following now

Connect-VIServer -Server "vmware_host" -Port 8333
get-vm sqldev2k8 | shutdown-vmguest

Tuesday, February 9, 2010

Keeping up with Microsoft

It seems that Microsoft releases new tools at an alarming rate. It feels like .Net 3.5 and Silverlight were just recently came to market, now Microsoft is at it again. Behold that .Net 4.0 and Visual Studio 2010 are just around the corner. Here is Scott Guthrie’s entry to confirm that, here.

From playing with Beta2 of VS 2010, I am highly looking forward to this release. They’ve made great strides at giving state of the art debugging, and visual design capabilities to developers.

The Beta2 and RC can both be installed side-by-side, so it’s time to play more with new stuff!!!

Thursday, February 4, 2010

Submitting Xml correctly into SOAP envelope

Over time, I became a bit comfortable for web services frameworks to take care of the serialization details. A few days ago, I had to deal with consuming the web service manually and quickly realized that i have not been below trenches in awhile.

The SOAP service has a string parameter which is in fact and xml fragment. Initially, I wrote the soap request in the following format:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <PersonalizedHelloWorld xmlns="http://tempuri.org/">
      <nameParameter><name>Roman</name></nameParameter>
    </PersonalizedHelloWorld>
  </soap:Body>
</soap:Envelope
Obviously, there is an issue with doing that. Can you spot it?

Well, you must use <![CDATA[]]> escaping syntax in the nameParameter element text. So the it should look like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <PersonalizedHelloWorld xmlns="http://tempuri.org/">
      <nameParameter><![CDATA[<name>Roman</name>]]></nameParameter>
    </PersonalizedHelloWorld>
  </soap:Body>
</soap:Envelope

Tuesday, January 12, 2010

Asp.Net Intrinsic properties

By default the System.Web.UI.Page exposes Session, Request, and Response properties.  However often you may want to access these properties outside of the Page context. The easiest way to do it is to use HttpContext.Current static property to obtain the current request’s HttpContext.  Thus, you can obtain a session variable like this:

HttpContext.Current.Session[“userid”].


Vote for two important CodePlex features

Eric Hexter, from MvcContrib project, has just asked the community to go and vote for a few issues with CodePlex. Here is his blog for reference, http://www.lostechies.com/blogs/hex/archive/2010/01/11/a-call-for-help-vote-for-my-codeplex-issues.aspx. Go Vote!

Monday, November 16, 2009

Windows Management Framework was released!

I always like playing with management tools for windows since dos days.  I think the release of Windows Management Framework at the end of October is truly the next step in Microsoft console/command-line tooling revolution.  Thank you, Jeffrey Snover.

Thursday, October 29, 2009

Web Goat – Interesting way to learn security on the Web.

As I deal more and more with web in my daily life, I realized that web security is a very intricate subject and tough to learn as well. The next iteration of CodeCamp is in town in a week, so I will have a chance to check out Web Goat. Due to time constraints, I wont be able to research beforehand, so it’s exciting to learn about something completely new.

Monday, May 25, 2009

Viewing temp table structure

For some reason I can never remember to properly retrieve connection specific temporary table’s structure, i.e. #tempCustomers. Due to the fact that the table resides in tempdb, this is the format required:

use tempdb
exec sp_help #tempCustomers
Highlight these two lines in Management studio and press F5!

Friday, May 8, 2009

Virtual Function Calls from Constructors/Finalizers … Bad Idea!

So I am skimming over this book, Framework Design Guidelines by Krzysztof Cwalina and Brad Abrams, when authors note to “avoid calling virtual members on an object inside its constructor”. At first a developer might not think about the danger but it does make sense with a quick example that authors provide.

Here is another one i cooked up:

public class Trans {
public abstract Log();
public Trans() {
Log(...);
}
}

public class SomeTrans:Trans {
private Logger logger;
public SomeTrans() {
logger = new Logger();
}
public override Log(...) {
if (logger == null)
Console.Write("Oops!");
else
logger.write(...);
}
}

Using the base class to execute common code that all derived classes will might seem like a good idea but here the Trans constructor calls the derived type’s Log method before SomeTrans constructor is called. Compiler is unable to detect this danger because binding happens at run-time so be very aware.

The rule of thumb is to never do that!

Also note, C++ behaves differently as it does not allow a virtual traversal because at base construction time the object type is Trans.

Wednesday, April 1, 2009

Managing IIS7 SSL settings without SSL binding

    I was messing around with IIS7 site settings and ran into the error when I tried to disable SSL requirement for access.

InvalidSSLSettings

It appears IIS does not allow you SSL settings modifications if  HTTPS binding was already removed.

Make sure you have Binding like this:

IIS7_https_binding

Tuesday, January 13, 2009

TypeMock Isolator 2.5 w/ VB.Net support

Programming Visual Basic applications?

Typemock have released a new version of their unit testing tool, Typemock Isolator 5.2.
This version includes a new friendly
VB.NET API which makes Isolator the best Isolation tool for unit testing A Visual Basic (VB) .NET application.

Isolator now allows unit testing in VB or C# for many ‘hard to test’ technologies such as SharePoint, ASP.NET MVC, partial support for Silverlight, WPF, LINQ, WF, Entity Framework, WCF unit testing and more.

Note that the first 25 bloggers who blog this text in their blog and tell us about it, will get a Free Full Isolator license (worth $139). If you post this in a VB.NET dedicated blog, you'll get a license automatically (even if more than 25 submit) during the first week of this announcement.

Go ahead, click the following link for more information on how to get your free license.

Monday, December 22, 2008

Converting Mail-Enabled recipient to Mailbox-Enabled recipient

    Out of the box, MS Exchange 2003/2007 do not offer any kind of way converting a mail-enabled recipient (MEU) into a mailbox-enabled recpieint (MBXU).  At first, you would think that scenario is least likely. Mail-enabled recipients forward to outside of exchange organization and why would you create a mailbox.  Well, in complex environments where organization has multiple email systems and a user wants to migrate to exchange but already utilizes AD, or if your organization is going through a complex migration.

    To convert an MEU into MBXU, we could just strip the AD object of exchange attributes and then ask exchange to create a mailbox.  However, you will notice that there might be side effects. Any secondary emails that might be attached to the MEU are now gone.  Secondly, a less trivial issue, is that repliability of emails which contain MEU address book entry is now broken. To fix these both, you’ll need to track secondary emails and legacyExchangeDn of the MEU and append them to proxyAddresses attribute when MBXU is created.


$userIdentity = 'testuser'
$mailboxDatabase = exserver\mbxdb'
$err = @()
$user = Get-MailUser -Identity $userIdentity `
-ErrorAction SilentlyContinue -ErrorVariable +err
if ($err.count -ne 0)
{
Write-Error '
The user is not a mail-enabled user.'
return;
}
$mbxDB = Get-MailboxDatabase -Identity $mailboxDatabase `
-ErrorAction SilentlyContinue -ErrorVariable +err
if ($err.count -ne 0)
{
Write-Error "The database value is incorrect."
return;
}
$extAddress = $user.ExternalEmailAddress
$currAddresses = $user.EmailAddresses
$legDn = $user.LegacyExchangeDn
Disable-MailUser $user -Confirm:$false | Out-Null
$mbxUser = Enable-Mailbox $user -Confirm:$false `
-Database $mailboxDatabase
$addresses = $mbxUser.EmailAddresses
if ($mbxUser.LegacyExchangeDn -ne $legDn) {
$addresses.add("X500:$legDn")
}
$currAddresses | ?{ $_ -ne $extAddress } | %{
if ( -not $addresses.Contains($_)) {
$addresses.Add($_) | Out-Null
}
}
if ($addresses.Changed) {
Set-mailbox $mbxUser `
-EmailAddresses $addresses | Out-Null
}

Thursday, December 18, 2008

C# Events and thread-safety


After reading “C# Programming Language”, which is more or less a dictionary of C# language features, I noticed that the spec claims thread-safety in event default accessors.

So code defined like this:

public event SomeEvent;
compiled into something roughly as this:
   1:  private EventHandler __SomeEvent;
   2:  public event SomeEvent {
   3:      add { lock(this) { __SomeEvent += value; }}
   4:      remove { lock(this) { __SomeEvent -= value; }}
   5:  }

Actually, add and remove keywords are translated as add_SomeEvent and remove_SomeEvent methods with [MethodImpl(MethodImplOptions.Synchronized)] attributes and thus equivalent to lock(this) shown above.

However, There is a problem here to achieve thread-safety. Using [MethodImpl(..)] is a bad practice b/c your code is trying to enter a monitor for this object instance. Thus, if another thread of execution obtains the monitor first, your subsequent call to “+=” or “-=” will block and will be hard to troubleshoot.

Instead consider this pattern where you implement custom accessors locking on a private object and give caller to invoke event safely through a method:

private object l_SomeEvent;
private EventHandler __SomeEvent;
public event SomeEvent {
add { lock(l_SomeEvent) { __SomeEvent += value; }}
remove { lock(l_SomeEvent) { __SomeEvent -= value; }}
}
public void OnSomeEvent(EventArgs e) {
EventHandler temp;
lock(l_SomeEvent) { temp = __SomeEvent; }
if (temp != null) { __SomeEvent(this,e); }
}

Tuesday, November 25, 2008

Using Export-Mailbox CmdLet to export to PST file

In order to export mail to a PST file, EMS requires an Outlook MAPI to be present. Otherwise,

11-17-2008_Error_ExportMailboxNot64bitCapable

That means you must use 32-bit version of the Exchange Management Tools on an Outlook-installed workstation because 64bit EMS process cannot load 32-bit MAPI subsystem.

Thus, I quickly ran through a Vista 32bit set up steps.

1. Install Outlook

2. Install IIS Requirements

11-19-2008-IIS_Options_Ex2k7MgmtTools

3. Install 32bit Exchange Management Tools, here.

Done!

Friday, October 17, 2008

New Drop of Gallio 3.0.4 is out

New drop of Gallio is up and ready. It has a number of feature improvements, discussed at here. My main concern is R# 4.1 integration.
Download it now at here.

Tuesday, July 22, 2008

Working with Active Directory Dates

Recently, my friend and colleague asked me about how to limit an ldap search to only return objects that were created after a certain date. 'whenCreated' should be a logical choice to solve that. However, this attribute has an interesting format, see this reference. So, i marked up a few functions to help us work with the date naturally within Powershell.
function ConvertToAdDate([DateTime]$date) {
"{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}.0Z" -f $date.year,$date.month, `
$date.day, $date.Hour, $date.Minute, $date.Second
}
function ConvertFromAdDate([String] $date) {
$pattern = `
'^(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hrs>\d{2})`
(?<min>\d{2})(?<sec>\d{2})\.0Z$
'
$match = [regex]::Match($date,$pattern)
if ($match.success) {
$result = New-Object System.DateTime($match.groups["year"].value,`
$match.groups["month"].value,$match.groups["day"].value,`
$match.groups["hrs"].value,$match.groups["min"].value, `
$match.groups["sec"].value,[DateTimeKind]::Utc)
$result.ToLocalTime()
}
else {
$null
}
}

Friday, July 11, 2008

Purging Mailboxes In Exchange 2003

I have recently demonstrated how to Purge a mailbox in Exchange 2007 but did not show anything for Exchange 2003. Here is what I do to purge mailboxes on Exchange 2003 server.

$list = gwmi -ComputerName "ex2k3srv" -Class Exchange_Mailbox -Namespace Root\MicrosoftExchangeV2 | ?{ $_.DateDiscoveredAbsentInDS -ne $null }
$list | %{ $_.Purge() }