Wednesday, July 6, 2011

Automatically create a 2010 exchange mailbox

SecureString password = new SecureString();
string str_password = "pass";
string username = "userr";

string liveIdconnectionUri = "http://exchange.wenatex.com/Powershell?serializationLevel=Full";

foreach (char x in str_password)
{
password
.AppendChar(x);
}

PSCredential credential = new PSCredential(username, password);

// Set the connection Info
WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credential
);

connectionInfo
.AuthenticationMechanism = AuthenticationMechanism.Default;

// create a runspace on a remote path
// the returned instance must be of type RemoteRunspace

Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);

PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();

command
.AddCommand("Enable-Mailbox");
command
.AddParameter("Identity", usercommonname);
command
.AddParameter("Alias", userlogonname);
command
.AddParameter("Database", "MBX_SBG_01");

powershell
.Commands = command;
try
{
// open the remote runspace
runspace
.Open();
// associate the runspace with powershell
powershell
.Runspace = runspace;
// invoke the powershell to obtain the results
return = powershell.Invoke();
}
catch (Exception ex)
{

Console.WriteLine(ex.Message);
}
finally
{
// dispose the runspace and enable garbage collection
runspace
.Dispose();
runspace
= null;
// Finally dispose the powershell and set all variables to null to free
// up any resources.
powershell
.Dispose();
powershell
= null;
}

Start Crawling With PowerShell

A while ago I blogged about starting a new crawl with PowerShell in this post, but today I got a bit further, each rollout I do on my dev machine a whole new site collection gets created using PowerShell, after that there is some test content provisioned (also using PowerShell), and finally the search settings are added. It kinda feels like everything is done through PowerShell. The point however is that I not only want to start a new crawl, but make sure that ‘old’ content is deleted. Step by step; I create some Crawled properties, create some Managed Metadata properties, create some scopes and finally delete the old content and crawl the new one.

The first part creating crawled properties and metadata properties i used this blog post. Getting me something like the following, that checks if the crawled property exists and if so gets it, otherwise creates it, then setting it into a metadata property that can be used. Nice to know is that the –propset property even though the documentation says its optional is in fact required!

1: # Get or create SPEnterpriseSearchMetadataCrawledProperty
2: if (Get-SPEnterpriseSearchMetadataCrawledProperty
3: -SearchApplication $searchapp -Name "proptocreate"
4: -ea "silentlycontinue") {
5: $crawlprop = Get-SPEnterpriseSearchMetadataCrawledProperty
6: -SearchApplication $searchapp -Name "proptocreate"
7: } else {
8: $crawlprop = New-SPEnterpriseSearchMetadataCrawledProperty
9: -SearchApplication $searchapp -VariantType 31
10: -Name proptocreate -IsNameEnum $false -PropSet "00130329-0000-0130-c000-000000131346"
11: }
12:
13: if (Get-SPEnterpriseSearchMetadataManagedProperty
14: -SearchApplication $searchapp -Identity "MetadataPorpertyExample"
15: -ea "silentlycontinue") {
16: write-host -f Green "MetaProperty already exists,
17: we delete it so it can be reacreated "
18: $prop = Get-SPEnterpriseSearchMetadataManagedProperty
19: -SearchApplication $searchapp -Identity "PublishingPageContent"
20: $prop.DeleteAllMappings()
21: $prop.Delete()
22: $searchapp.Update()
23: } else {}
24:
25: write-host -f Green "Try to create MetaProperty"
26: $prop = New-SPEnterpriseSearchMetadataManagedProperty
27: -SearchApplication $searchapp -Name "PublishingPageContent" -Type 1
28: $prop.EnabledForScoping = $true
29: $prop.Update()
30:
31: New-SPEnterpriseSearchMetadataMapping -SearchApplication
32: $searchapp -ManagedProperty $prop -CrawledProperty $crawlprop


After that i can create scopes (my colleague Peter found it out), where I check if a scope already exists and if so delete it so it can be recreated again:

1: if (Get-SPEnterpriseSearchQueryScope -SearchApplication $searchapp
2: -Identity "ScopeExample" -ea "silentlycontinue") {
3: write-host -f Green "Scope already exists,
4: we delete it so it can be reacreated "
5: $scope= Get-SPEnterpriseSearchQueryScope -SearchApplication
6: $searchapp -Identity "ScopeExample"
7: $scope.Delete();
8: $searchapp.Update();
9: } else {}
10:
11: # Create "ScopeExample" scope
12: $scope = New-SPEnterpriseSearchQueryScope -Name "ScopeExample"
13: -Description "Doorzoek alle informatie" -SearchApplication $searchapp
14: -DisplayInAdminUI $true
15:
16: New-SPEnterpriseSearchQueryScopeRule -RuleType AllContent
17: -Url $url -scope $scope


And after that in finally can reset my index, and make sure everything is found:

1: Write-Host -f Green "Delete current index ...";
2: $searchapp.Reset($true, $true)
3:
4: Write-Host -f Green "Start indexing and scopecompilation ";
5: $searchapp.StartScopesCompilation()
6:
7: $CrawlContents = Get-SPEnterpriseSearchServiceApplication
8: | Get-SPEnterpriseSearchCrawlContentSource
9:
10: foreach ($crawlcontent in $CrawlContents)
11: { $crawlcontent.StartFullCrawl(); }

Thursday, May 26, 2011

Skype has stopped working

A small number of you may have had problems signing in to Skype. This predominantly affects people using Skype for Windows. Skype has identified the problem and will issue a fix in the next few hours.

In the meantime, you can follow the steps below to fix the problem manually.

Windows

  1. If the Skype icon is displayed in the system tray at the bottom right of the screen, right-click it and select Quit.
  2. Click Start, type "run" and press Enter. (On Windows XP: Click Start and then Run.)
  3. Type "%appdata%\skype" and click OK.
  4. Locate and delete the file shared.xml. The file may be displayed as shared if file extensions are not displayed by default on your computer.
  5. If you cannot find this file:
    • Click Start, type "run" and press Enter. (On Windows XP: Click Start and then Run.)
    • Type "control folders" and click OK.
    • In the View tab, ensure that Show hidden files and folders is enabled.
    • Repeat the instructions from the beginning.
  6. Restart Skype.

Mac

  1. Open Finder and locate the following folder:
  2. ~/Library/Application Support/Skype

  3. Delete the file shared.xml.
  4. Restart Skype.

The ~ sign means your home folder. You can find your home folder by opening Finder and selecting Go> Home from the menu bar or pressing Command (Apple), Shift and H keys at the same time.

Linux

  1. Go to the following folder:
  2. /home/YourLinuxUserName/.Skype

  3. Delete the file shared.xml.
  4. Restart Skype.

The Skype folder is a hidden folder - please check Show hidden files in your file browser to view and access it.

Monday, February 28, 2011

Introducing SharePoint 2010

Welcome to Introducing SharePoint 2010, the first book on SharePoint 2010, introducing you to what’s new in Microsoft’s next version of its collaboration platform. Throughout the issue, you will learn all you need to get started working with SharePoint 2010, whether you are a developer, an administrator, or an end user.

Throughout more than 180 pages, you will learn about SharePoint 2010 through several chapters:

SharePoint 2010 New Features Overview
Get an overview of the new features of SharePoint 2010. In addition, I’ll walk you through installing SharePoint 2010 Beta 2 in a 40 minute video, including installing Active Directory, SQL Server 2008, and the pre-requisites for SharePoint 2010.

Getting Started with SharePoint 2010
This issue will get you started with SharePoint 2010 in record time and walk you through several exercises to show you many of the new features in action. I’ll also show you, in four accompanying videos, how to set up a metadata model in SharePoint.


Visual Studio 2010 and SharePoint
SharePoint Designer 2010

SharePoint Designer 2010 offers massive improvements over the previous version. I’ll walk you through this new version, including setting up your first SharePoint Designer workflow using the new workflow editor.

Visual Studio 2010 completely changes the playing field for SharePoint development. Find out what features will benefit you and if this tool is really for you.

The New SharePoint 2010 Developer
It’s time to learn what the new SharePoint 2010 development model means for you as a developer. I’ll walk you through what you need to learn in order to harness the new features of SharePoint, including the client object model, LINQ to SharePoint, REST and WCF services, using the new UI features, and more!

SharePoint 2010 Administrator Update
The administrator’s job gets a whole lot easier in SharePoint 2010. I’ll walk you through the features that will make your life easier as an IT-pro, including upgrading sites from SharePoint 2007, PowerShell (I promise to make it easy), managing a SharePoint 2010 farm and performance and monitoring.

Wednesday, October 6, 2010

Create a Custom NewForm.aspx for a SharePoint List

SharePoint has a number of features when it comes to working with its built-in lists. One of these is that it automatically generates New (NewForm.aspx), Edit (EditForm.aspx) and Display (DispForm.aspx) for each list when it is created. While this is very useful, it is somewhat limited when you want to customize what is displayed, or how information is displayed on these pages.

The answer to this problem is SharePoint Designer. In the following scenario, I will show you how to customize the NewForm.aspx page for a SharePoint List using SharePoint Designer.

Your company wants to set up a Computer Equipment Request List to handle new requests that the employees have for the IT Department. So, you go and create the list in SharePoint. All is great until you realize that the majority of the information in the list is for internal IT use, and should not be presented to the end-user to fill out.

All you really want the end-user to complete is the fields, Request Name, Description, and Requested Equipment.

This is where SharePoint Designer comes to the rescue. By completing these steps, you will be customizing your own NewForm.aspx in no time.

  1. Open SharePoint Designer.
  2. Open the Site where your list resides.
  3. In the Folder List window select the Computer Equipment Request list.
  4. Right-click on the NewForm.aspx and select New From Existing Page. This creates a new page based on the original NewForm page. It is a bad idea to modify the default NewForm page, for if you need to revert back to the original, which could prove to be a difficult task. In some cases, this may require re-creating the list.

  5. Now, in the main editor window, select the List placeholder and click on the (arrow) that appears in the upper-right corner. This will bring up the Common Content Tasks List, and then select Default to Master's Content.

    Click Yes on the message box that appears.

  6. Then, you will want to select the PlaceHolderMain(Master) Content Place Holder, click on the that appears in the upper-right corner and select Create Custom Content.

  7. Next, click inside the PlaceHolderMain(Custom) and make sure that you can see the cursor inside the selected area.
  8. After this, in the SharePoint Designer File Menu, select Insert -> SharePoint Controls -> Custom List Form.

  9. In the pop-up box that appears, select the Computer Equipment Request list, and make sure that Item is selected for "Content type to use for form". You'll also want to make sure that New item form is the selected option. As for the Show standard toolbar checkbox, this depends on how you will be using your custom List Form, but for this example, uncheck this checkbox.

  10. After this, in the main edit window, you will now see a custom list form control that can be customized as needed.
  11. For our custom New Form, we need to remove the extra fields that we do not want the end-users to fill out (or see). To do this, select somewhere in the field row that you want to remove (in this case, the Status field). Then right-click and select Delete -> Delete Rows. This will then remove that field row from the custom list form control. Repeat this step for all the fields you want to remove.

  12. Once we have removed all fields we don't want to be displayed, we are left with Request Name, Description, and Requested Equipment.

  13. Now that we have our custom NewForm looking how we want it to, we need to save it in SharePoint so that we can use it. To do this, click on the Save button, and then navigate to the Computer Equipment Request list and look for the original NewForm.aspx page. For this example, we are naming the page SubmitForm.aspx.

  14. Finally, we will want to set our custom NewForm (SubmitForm.aspx) as the default New item form for our list. To do this, go back to the Folder List window select the Computer Equipment Request list and right-click on it. From the menu that appears, select the Properties option.

  15. In the pop-up box, make sure that Item is selected for "Content type specific forms". Then click on the Browse button for the New item form to select our custom SubmitForm.aspx.

  16. Now your custom NewForm page is ready for use. This is how it will appear to the end-user when they create a new item for the Computer Equipment Request list.

By following the above instructions, you will be creating your own customized NewForm.aspx pages in no time using SharePoint Designer. The same techniques can also be applied to creating custom EditForm.aspx and DispForm.aspx pages.

Next time, I'll show you how to apply these concepts to creating multiple custom EditForm.aspx pages to use with different user roles.